python - 在python中请求GET后得到400个错误请求
问题描述
我想将此 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)
任何建议将不胜感激。谢谢。
解决方案
您应该使用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)
推荐阅读
- c# - 如何在每个标签中记录每个数字进行计算?
- aspnetboilerplate - 从 Angular 上传文件 - 将文件内容设置为 Dto
- python - 将新工作表添加到 2000 xlsx 文件 - Openpyxl 非常慢
- elixir - 是否可以在 ecto 查询中对预加载进行选择?
- python - 检查excel表中是否存在pandas DataFrame系列中的值
- magento-2.3 - 所有类别设置为noindex,follow
- c# - 可空引用类型和 ToString() 重载
- amazon-s3 - How to grant public read only access to S3 Bucket in AWS SAM template
- android - Flutter 需要 Android SDK 28 和 Android BuildTools 28.0.3
- c# - 使用 C# 客户端连接到 socket.io,但使用/加入房间