自适应付款支付API错误580001

时间:2013-08-22 23:00:08

标签: python paypal paypal-adaptive-payments error-code

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

使用我的凭据进行卷曲工作,它只是通过urrllib失败了。我读了其他同样的错误代码,偶然发送了一个HTTP GET,我已经通过request.get_method()确认这确实是POSTing。有什么想法吗?

1 个答案:

答案 0 :(得分:4)

在发布后十分钟计算出来。典型

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

payload = urllib.urlencode(payload)

import cjson
payload = cjson.encode(payload)

作品!太糟糕的贝宝不会返回任何信息性的错误信息。