2013-08-22 96 views
2

我正在向paypal自適應付款API發出PAY請求,並得到一個沒有附加信息的通用錯誤ID 580001。自適應付款付款API錯誤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": "[email protected]" 
      }] 
     }, 
     # 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。有任何想法嗎?

+0

你可以發佈整個python腳本以及工作curl命令嗎? – Dennis

+0

感謝丹尼斯,我在下面發佈了答案。 – sara

回答

3

在發佈後十分鐘就能發現它。典型。

我將請求數據格式指定爲JSON,但後來是對請求數據進行url編碼。更改

payload = urllib.urlencode(payload) 

import cjson 
payload = cjson.encode(payload) 

作品!太糟糕的貝寶不會返回任何信息性的錯誤信息。

+0

很高興聽到:) – Dennis