【问题标题】:Sending post request to PayPal to get access token in Django向 PayPal 发送发布请求以在 Django 中获取访问令牌
【发布时间】:2019-09-11 00:11:06
【问题描述】:

我正在尝试向 PayPal 发送发布请求以获取访问令牌以开始执行更多请求。

它给了我401 Unauthorized 错误,这是我的代码

def buy_confirm(request, amount, price, server_name, char_name):
    if request.method == 'POST':
        client_id = 'xxxxxxxxxxxxxxxxxxxxx'
        client_secret = 'xxxxxxxxxxxxxxxxx'
        headers = {
            'Content-Type':'application/x-www-form-urlencoded',
            'Authorization':"Basic " + client_id + ' ' + client_secret
        }
        body = {
            'grant_type':'client_credentials'
        }
        r = requests.post("https://api.sandbox.paypal.com/v1/oauth2/token",body, headers)
        print(r.status_code, r.reason)
    return render(request, 'buy_confirm.html')

【问题讨论】:

    标签: python django api paypal


    【解决方案1】:

    发现我必须把它改成这样:

    def buy_confirm(request, amount, price, server_name, char_name):
        if request.method == 'POST':
            client_id = 'xxxxxxxxxxxxxx'
            client_secret = 'xxxxxxxxxxxxxxx'
            headers = {
                'Content-Type':'application/x-www-form-urlencoded',
            }
            body = {
                'grant_type':'client_credentials'
            }
            r = requests.post("https://api.sandbox.paypal.com/v1/oauth2/token",body, headers, auth=(client_id, client_secret))
            print(r.status_code, r.reason)
        return render(request, 'buy_confirm.html')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-09
      • 1970-01-01
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多