3

我正在 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}"}
             ]
 }

使用我的凭据进行卷曲,它只是通过 urlllib 失败。我读到其他具有相同错误代码的人意外发送了 HTTP GET,我通过 request.get_method() 确认这确实是 POST。有任何想法吗?

4

1 回答 1

4

发帖十分钟后想通了。典型的。

我将请求数据格式指定为 JSON,但随后对请求数据进行了 url 编码。改变

payload = urllib.urlencode(payload)

import cjson
payload = cjson.encode(payload)

作品!太糟糕了,贝宝不返回任何信息性错误消息。

于 2013-08-23T18:52:45.623 回答