【问题标题】:How to pass Oauth2.0 parameters to put request using python如何使用python传递Oauth2.0参数来提出请求
【发布时间】:2021-04-28 23:14:42
【问题描述】:

有没有办法将以下参数传递给 post 服务?

我尝试了多种方法,但都不起作用

import requests

auth = {
    'client_id' : 'telegram',
    'client_secret' : 'Welcome1',
    'username' : 'ut1',
    'password' : '123'
    'Access Token URL' : 'https://api.github.com/token'
}

r = requests.post('https://api.github.com', auth= auth,  verify=False)

【问题讨论】:

  • 您尝试过哪些选项?你得到什么结果?任何具体的错误信息?您在发出 post 请求时遇到问题还是在获取令牌时遇到问题?顺便说一句 - 你确定你可以从 Github 获得一个令牌吗?您是否尝试过任何教程?

标签: python oauth-2.0


【解决方案1】:

我在 headers 参数中传递 Oauth2.0 参数,这对我有用。

def sendVerificationCodeSMS(tokenUrl, clientID, clientSecret, username, password, phoneNumber):
headers  =  {
                'Access Token URL': tokenUrl
                ,'Client ID': clientID
                ,'Client Secret': clientSecret
                ,'Username': username
                ,'Password': password
} 

response = requests.post('https://github.com/' + str(phoneNumber), headers = headers, verify=False) 

if (response.status_code == 201):
    try:
        response = response.json()
        verifCode = response["verificationCode"]
        return verifCode
        # print(verifCode)
    except:
        # print("Error al generar código de verificación")
        verifCode = 0
        return verifCode
else:
    print("No se ha podido enviar el código de verificación, intente nuevamente")

【讨论】:

    猜你喜欢
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多