【问题标题】:How do I do a GET request with multiple headers?如何使用多个标头执行 GET 请求?
【发布时间】:2019-06-27 01:19:18
【问题描述】:

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

我尝试将 Content-Type 和 Authorization 周围的 '' 更改为 "",因为我在这里看到过涉及两者的帖子,但似乎都不起作用。这是我的代码。

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)

我应该得到答案,但在授权后我在“:”处收到语法错误

【问题讨论】:

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


    【解决方案1】:

    您没有在键值对之后放置逗号

    【讨论】:

      【解决方案2】:
      headers = {
      
              'Content-type': 'application/json'
              'Authorization': 'Bearer placeholdertoken'
      }
      

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

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

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

      【讨论】:

        猜你喜欢
        • 2017-04-14
        • 1970-01-01
        • 2019-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-23
        • 2016-09-01
        • 1970-01-01
        相关资源
        最近更新 更多