gpt4 book ai didi

python - 为什么我在 Django 中使用此调用从 Paypal 获取 'internal error'?

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:35 25 4
gpt4 key购买 nike

我有一个获取 PayPal 身份验证的请求。它是用 Curl 编写的,并且运行良好。尝试用 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\"}}"

python

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()

关于python - 为什么我在 Django 中使用此调用从 Paypal 获取 'internal error'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18582138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com