【问题标题】:get 400 bad request after requesting GET in python在python中请求GET后得到400个错误请求
【发布时间】:2021-10-19 03:52:25
【问题描述】:

我想把这个 curl 命令转换成 python 脚本

curl -v -H "Content-Type: application/json" -H "Authorization: Bearer MYTOKEN" https://www.zopim.com/api/v2/chats

我在下面编写了 python 脚本,但我得到了<Response [400]>并且不起作用。

import requests

url = "https://www.zopim.com/api/v2/chats"
access_token = "MYTOKEN"

response = requests.post(url,
      headers={"Content-Type":"application/json;charset=UTF-8",
               "Authorization": "Bearer {}".format(access_token)})
print(response)

任何建议将不胜感激。谢谢。

【问题讨论】:

  • 尝试翻转标题的顺序并删除;charset=UTF-8
  • 感谢您的评论,但即使这样做也没有任何改变......
  • 检查令牌,是否过期以及需要多长时间才能过期。
  • 打印出响应的实际正文可能是个好主意。它可能包含有用的错误消息。
  • 我创建了一个新令牌并替换它,但仍然得到 400...

标签: python get request zendesk


【解决方案1】:

你应该使用requests.get而不是requests.post,因为你想要的是一个GET请求:

import requests

url = "https://www.zopim.com/api/v2/chats"
access_token = "MYTOKEN"

response = requests.get(url,
      headers={"Content-Type":"application/json;charset=UTF-8",
               "Authorization": "Bearer {}".format(access_token)})
print(response)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-08
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多