我正在尝试使用TransactionSearch API调出商家交易历史记录。我一直被困在“安全标头无效错误”中,在其他帖子中找不到解决方案。我的代码在沙盒服务器上运行良好,并且我从PayPal生成了实时凭证和签名。我认为如果他们给了我凭据,我就有权访问该API。

我的python代码如下:

import requests
def getTransactionHistory(start_datetime, end_datetime):
    headers = {'X-PAYPAL-SECURITY-USERID' : api_username, 'X-PAYPAL-SECURITY-PASSWORD' : api_password,
               'X-PAYPAL-SECURITY-SIGNATURE' : api_sig}
    data = 'USER=' + api_username + '&PWD=' + api_password + '&SIGNATURE=' + api_sig + '&METHOD=' + \
           'TransactionSearch' + '&STARTDATE=' + start_datetime + '&ENDDATE=' + end_datetime + \
    '&VERSION=94'
    print data
    req = requests.post(base+nvp_point, data=data)
    return req.text

r = getTransactionHistory('2012-01-01T05:38:48Z', '2012-01-02T05:38:48Z')

最佳答案

上面的代码是正确的。我的签名或密码中有一个“-”,但未正确粘贴。解决了。

关于python - 安全 header 无效(python),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34781427/

10-12 03:33
查看更多