我在 python 中向 paypal 自适应支付 API 发出 PAY 请求,并收到一个没有其他信息的一般错误 ID 580001。
headers = {
# API credentials for the API caller business account
'X-PAYPAL-SECURITY-USERID': config.PAYPAL_API_USER_ID,
'X-PAYPAL-SECURITY-PASSWORD': config.PAYPAL_API_PASSWORD,
'X-PAYPAL-SECURITY-SIGNATURE': config.PAYPAL_API_SIGNATURE,
'X-PAYPAL-APPLICATION-ID': 'APP-80W284485P519543T',
'X-PAYPAL-REQUEST-DATA-FORMAT': 'JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON'
}
payload = {
"actionType": "PAY",
"currencyCode": "USD",
"receiverList": {
"receiver": [{
"amount": "1.00",
"email": "sandbox_test_user_email@gmail.com"
}]
},
# where the sender is redirected
"returnUrl": config.SUCCESS_URL,
"cancelUrl": config.SUCCESS_URL,
"requestEnvelope": {
"errorLanguage":"en_US",
# error detail level
"detailLevel":"ReturnAll"
}
}
import urllib2, urllib
payload = urllib.urlencode(payload)
request = urllib2.Request(url='https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
data=payload,
headers=headers)
f = urllib2.urlopen(request)
contents = f.read()
响应:
{"responseEnvelope":
{"timestamp":"2013-08-22T15:44:50.97507:00",
"ack":"Failure",
"correlationId":"df4f39293971f",
"build":"6941298"
},
"error"[ {"errorId":"580001",
"domain":"PLATFORM",
"subdomain":"Application",
"severity":"Error",
"category":"Application",
"message":"Invalid request: {0}"}
]
}
使用我的凭据进行 curl 是可行的,只是通过失败的 urrllib。我读到其他具有相同错误代码的人无意中发送了 HTTP GET,我已经通过 request.get_method() 确认这确实是 POSTing。有什么想法吗?
最佳答案
发帖十分钟后想通了。典型。
我指定请求数据格式为JSON,然后是url对请求数据进行编码。改变
payload = urllib.urlencode(payload)
到
import cjson
payload = cjson.encode(payload)
有效!太糟糕了,paypal 没有返回任何信息性错误消息。
关于python - 自适应支付支付 API 错误 580001,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18392145/