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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top