Adaptive Payments Pay API Error 580001

倾然丶 夕夏残阳落幕 提交于 2019-12-12 15:56:21

问题


I'm making a PAY request to the paypal adaptive payments API in python and getting a generic error id 580001 with no additional information.

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

Response:

    {"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}"}
             ]
 }

Curling with my credentials works, it's just going through urrllib that's failing. I read others with the same error code were sending an HTTP GET by accident, I have confirmed via request.get_method() that this is indeed POSTing. Any ideas?


回答1:


Figured it out like ten minutes after posting. Typical.

I specified the request data format as JSON, but then was url encoding the request data. Changing

payload = urllib.urlencode(payload)

to

import cjson
payload = cjson.encode(payload)

works! Too bad paypal doesn't return any informative error message.



来源:https://stackoverflow.com/questions/18392145/adaptive-payments-pay-api-error-580001

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!