如何执行具有多个标头的GET请求?

时间:2019-06-27 01:19:18

标签: python json python-3.x api python-requests

尝试将多个标头放入我的GET请求中时出现语法错误。

我尝试将“内容类型和授权”周围的“”更改为“”,因为我在这里看到了涉及两者的帖子,但似乎都没有用。这是我的代码。

import json
import requests
url = 'https://api.website.com/testpost'
headers = {

        'Content-type': 'application/json'
        'Authorization': 'Bearer placeholdertoken'
}
response= requests.get(url, headers=headers)
print(response)

我应该得到一个答案,但是授权后在“:”处出现语法错误

2 个答案:

答案 0 :(得分:2)

您没有在键值对后面加上逗号

答案 1 :(得分:1)

headers = {

        'Content-type': 'application/json'
        'Authorization': 'Bearer placeholdertoken'
}

这不是创建字典的正确语法。.您缺少key: value对之间的逗号。

更新代码以添加逗号,如下所示:

headers = {
    'Content-type': 'application/json',
    'Authorization': 'Bearer placeholdertoken'
}
相关问题