使用python和django,我试图使用REST API帐户付款资源在PayPal上创建付款。当我使用卷曲时,一切正常。在Django视图中,我得到了令牌,但是当我尝试使用它进行付款时,出现“HTTP Error 401:Unauthorized”错误。Paypal Rest API - 使用PayPal帐户付款资源创建付款
这里是我的卷曲的作品:
curl -v https://api.sandbox.paypal.com/v1/payments/payment -H 'Content-Type:application/json' -H 'Authorization:Bearer ***my_token***' -d '{ "intent":"sale", "redirect_urls":{ "return_url":"http://www.myurl.com", "cancel_url":"http://www.myurl.com"}, "payer":{ "payment_method":"paypal" },"transactions":[{"amount":{ "total":"0.10", "currency":"USD"},"description":"This is the Test payment transaction description."}]}'
这里是有当我的问题Django的看法:
import urllib2, base64
token = "***my_token***"
values = {
"intent":"sale",
"redirect_urls":{
"return_url":"http://www.myurl.com",
"cancel_url":"http://www.myurl.com"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"0.10",
"currency":"USD"
},
"description":"This is the Test payment transaction description."
}
]}
data = urllib.urlencode(values)
request1 = urllib2.Request("https://api.sandbox.paypal.com/v1/payments/payment")
base64string = base64.encodestring('%s' % token).replace('\n', '')
request1.add_header("Content-Type", "application/json")
request1.add_header("Authorization", "Bearer %s" % base64string)
result1 = urllib2.urlopen(request1 , data)
response = result1.read()
换句话说,我努力使卷曲工作在我视图。
谢谢。
'request1 = urllib2.Request( “https://www.sandbox.paypal.com/cgi-bin/webscr”)' – catherine 2013-03-16 01:14:55
@catherine。我期待有一个令牌的JSON数据,但使用您的地址带我到PayPal屏幕没有任何形式。 – user1783848 2013-03-16 02:13:28
我有同样的问题,你找到的任何解决方案? – 2013-07-16 20:11:39