使用Python搜索Paypal交易

使用Python搜索Paypal交易,python,python-2.7,paypal,paypal-sandbox,Python,Python 2.7,Paypal,Paypal Sandbox,我有必要的身份验证详细信息,我正在尝试进行TransactionSearch。我一直收到一个错误: 时间戳=2013%2d09%2d07T19%3a06%3a35Z&CORRELATIONID=b7af040415e92&ACK=Failure&VERSION=0%2000000&BUILD=7507921&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication%2Authorization%20失败&L_LONGMESSAGE0=0%20您%20没有

我有必要的身份验证详细信息,我正在尝试进行TransactionSearch。我一直收到一个错误: 时间戳=2013%2d09%2d07T19%3a06%3a35Z&CORRELATIONID=b7af040415e92&ACK=Failure&VERSION=0%2000000&BUILD=7507921&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication%2Authorization%20失败&L_LONGMESSAGE0=0%20您%20没有%20权限%20进行%20此%20API%20调用和L_SEVERITYCODE0=Error

这是我的密码:

(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()
(时间戳,签名)=signaturegen.getAuthHeader(apiUser=settings.USERNAME,apiPass=settings.PASSWORD,accessTok=res2[“token”],secTok=res2[“tokenSecret”],httpMethod=“POST”,scriptURI=”https://api-3t.sandbox.paypal.com/nvp")    
#上述操作用于生成时间戳和签名
headers={“X-PAYPAL-AUTHORIZATION”:“timestamp=“++”,token=“++”,signature=“+,“SUBJECT”:设置。}
数据={
“方法”:“TransactionSearch”,
“起始日期”:“2012-01-01T05:38:48Z”,
}
req=urllib2.请求(“https://api-3t.sandbox.paypal.com/nvp,simplejson.dumps(数据),标头)
res=urllib2.urlopen(req.read)()

我终于修复了代码,以下是完整版本:

import ast
import signaturegen
headers = {
    "X-PAYPAL-SECURITY-USERID": "xxxxxxxxx.xxxx.com",
    "X-PAYPAL-SECURITY-PASSWORD": "xxxxxxxx",
    "X-PAYPAL-SECURITY-SIGNATURE":  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T", #APP ID for sandbox

}


    headers = {
    "X-PAYPAL-SECURITY-USERID": settings.USERNAME,
    "X-PAYPAL-SECURITY-PASSWORD": settings.PASSWORD,
    "X-PAYPAL-SECURITY-SIGNATURE": settings.SIGNATURE,
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T"
}

    data = {"scope":"TRANSACTION_SEARCH", "callback":"http://www.example.com/success.html", "requestEnvelope": {"errorLanguage":"en_US"}}
    req = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/RequestPermissions/", simplejson.dumps(data), headers)    
    res = ast.literal_eval(urllib2.urlopen(req).read())
    token = res['token']
    red_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token=%s" % token
   if red_url:
        return HttpResponseRedirect(red_url)
    token = "xxxxxxxxxxxxxxxxxx"
    verification = "xxxxxxxxxxxxxxxxxx"
    headers2 = {
    "X-PAYPAL-SECURITY-USERID": "xxxxxxxxxxxx",
    "X-PAYPAL-SECURITY-PASSWORD": "xxxxxxxxxxxxxxxx",
    "X-PAYPAL-SECURITY-SIGNATURE": "xxxxxxxxxxxxx",
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T",
}
    url = "https://svcs.sandbox.paypal.com/Permissions/GetAccessToken/"


    dat2 = {
        "requestEnvelope": {"errorLanguage":"en_US"}, 
        "token": "AAAAAAAYcambja9iJfUw", 
        "verifier": "iVUJ6c-6ZNk8M6Q9hkC12A"}
    req2 = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/GetAccessToken/", simplejson.dumps(dat2), headers2)
    res2 = ast.literal_eval(urllib2.urlopen(req2).read())


    (timestamp, signature) = signaturegen.getAuthHeader(apiUser="xxxxxxxxxxxx", apiPass="xxxxxxxxxxxxxxxx", accessTok=res2["token"], secTok=res2["tokenSecret"], httpMethod="POST", scriptURI="https://api-3t.sandbox.paypal.com/nvp")    

    ultimate = {"X-PAYPAL-AUTHORIZATION": "timestamp="+timestamp+",token="+res2["token"]+",signature="+signature, "SUBJECT": settings.USERNAME}

    da = {
        "METHOD": "TransactionSearch",
        "STARTDATE": "2012-01-01T05:38:48Z",
    }
    req3 = urllib2.Request("https://api-3t.sandbox.paypal.com/nvp", urllib.urlencode(da), ultimate)
    res3 = urllib2.urlopen(req3).read()

由于代码中存在多个语法错误,因此无法运行此代码;它甚至不会到达您的声明要接收的错误。哪些语法错误??它运行并产生我上面发布的错误。
不是有效的Python。也不是
。这些只是占位符…我不想在这里发布我的沙盒凭据。