为什么我在 Django 中使用此调用从PayPal获得'internal error'?



我有一个获得PayPal身份验证的请求。它是用卷发写的,效果很好。试图在Python中重写它会导致错误响应(500000个内部错误)。有人能告诉我如何重写或更正我现有的代码吗。

CURL

curl -s --insecure -H "X-PAYPAL-SECURITY-USERID: <user_id>" -H "X-PAYPAL-SECURITY-PASSWORD: <user_password>" -H "X-PAYPAL-SECURITY-SIGNATURE: <user_signature>" -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" -H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" -H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" https://svcs.sandbox.paypal.com/Permissions/RequestPermissions -d "{"scope":"EXPRESS_CHECKOUT", "callback":"<callback_url>",  "requestEnvelope": {"errorLanguage":"en_US"}}"

巨蟒

import settings
import urllib
import urllib2
from django.utils import simplejson
def home(request):
    headers = {
    "X-PAYPAL-SECURITY-USERID": settings.USERNAME,
    "X-PAYPAL-SECURITY-PASSWORD": settings.PASSWORD,
    "X-PAYPAL-SECURITY-SIGNATURE": settings.SIGNATURE,
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T"
    }
    data = {"scope":"EXPRESS_CKECKOUT", callback":"http://www.example.com/success.html", "requestEnvelope": {"errorLanguage":"en_US"}}
    req = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/RequestPermissions/", simplejson.dumps(data), urllib.urlencode(data), headers)    
    res = urllib2.urlopen(req).read()

"EXPRESS_CKECKOUT"而不是"EXPRESS_CHECKOUT"中的拼写错误,不需要urllib2.Request的第三个参数urllib.urlencode(data)

data = {"scope":"EXPRESS_CHECKOUT", "callback":"http://www.example.com/success.html", "requestEnvelope": {"errorLanguage":"en_US"}}
req = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/RequestPermissions/", simplejson.dumps(data), headers)
res = urllib2.urlopen(req).read()

相关内容

  • 没有找到相关文章

最新更新