如何使用Python对Paypal API进行TransactionSearch调用

时间:2013-09-04 13:26:13

标签: python paypal paypal-sandbox

我有必要的身份验证详细信息,我正在尝试执行TransactionSearch。我一直收到错误:              的 ACK =失败&安培; L_ERRORCODE0 = 81002&安培; L_SHORTMESSAGE0 =未指定%20Method&安培; L_LONGMESSAGE0 =方法%20Specified%图20是%20not%20Supported&安培; L_SEVERITYCODE0 =错误

这是我的代码:

(timestamp, signature) = signaturegen.getAuthHeader(apiUser=settings.USERNAME, apiPass=settings.PASSWORD, accessTok=res2["token"], secTok=res2["tokenSecret"], httpMethod="POST", scriptURI="https://api-3t.sandbox.paypal.com/nvp")    
#the above operation is used to generate the timestamp and signature

headers = {"X-PAYPAL-AUTHORIZATION": "timestamp="+<timestamp>+",token="+<token>+",signature="+<signature>, "SUBJECT": settings.<API_USERNAME>}

data = {
"METHOD": "TransactionSearch",
"STARTDATE": "2012-01-01T05:38:48Z",
    }
req= urllib2.Request("https://api-3t.sandbox.paypal.com/nvp", simplejson.dumps(data), headers)
res = urllib2.urlopen(req).read()

我做错了什么。

1 个答案:

答案 0 :(得分:0)

对商家nvp API使用urllib.urlencode代替simplejson.dumps

req= urllib2.Request("https://api-3t.sandbox.paypal.com/nvp", urllib.urlencode(data), headers)