在post方法中传递标头以访问令牌

时间:2020-02-25 10:25:30

标签: python post

我正在尝试在post方法中传递标头以生成访问令牌。但是我越来越担心语法无效。我的标头代码如下

headers=("Authorization: Basic RXadsdsdsdsdsdsdsdsdjkfhsuidhsuihf==","Content-Type: application/x-www-form-urlencoded")

headers=('Authorization': 'Basic RXadsdsdsdsdsdsdsdsdjkfhsuidhsuihf==','Content-Type': 'application/x-www-form-urlencoded')

2 个答案:

答案 0 :(得分:1)

假设您使用的是Requests,则标题应该是字典,因此:

headers={
    "Authorization": "Basic RXadsdsdsdsdsdsdsdsdjkfhsuidhsuihf==",
    "Content-Type": "application/x-www-form-urlencoded"
}

答案 1 :(得分:1)

您可以尝试以下代码:

auth_token = "Basic {}".format(token)
headers = {'Content-Type': 'application/json', 'Authorization': auth_token}