使用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