【发布时间】:2016-12-21 12:05:08
【问题描述】:
我正在尝试使用 paypal Rest API 创建付款,但我不断收到此错误响应:
{"name":"MALFORMED_REQUEST","message":"The request JSON is not well formed.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"262cbdc417df7"}
这里是我的代码:
payment_url = 'https://api.sandbox.paypal.com/v1/payments/payment'
headers = {"Content-Type": "application/json", "Authorization": "Bearer %s" % access_token}
data = {
"intent": "sale",
"redirect_urls": {
"return_url": "http://localhost:8080/index.html",
"cancel_url": "http://localhost:8080/index.html"
},
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "7.47",
"currency": "USD"
},
"details": {
"subtotal": "7.41",
"tax": "0.03",
"shipping": "0.03"
},
"description": "This is the payment transaction description.",
"item_list": {
"items": [
{
"quantity": "1",
"name": "item",
"price": "7.41",
"currency": "USD",
"sku": "item"
}]
}
}
]
}
print headers
print data
r = requests.post(payment_url, headers=headers, data=data)
print 'payment res', r.text
而我只得到这样的回应:
{"name":"MALFORMED_REQUEST","message":"The request JSON is not well formed.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"262cbdc417df7"}
我已经看到很多关于这种错误的问题,但他们都没有解决方案。 :( json 格式的 post 数据显然是有效的。否则,请求 post 方法会引发异常。并且响应是从贝宝服务器返回的,但我无法从它提供的链接中找到任何信息。我检查了 Rest API 文档,我认为我提出的请求与示例完全一样。我错过了什么?
我们将不胜感激任何建议或解决方案。
【问题讨论】: