python - 为什么 github API python POST 请求不起作用?
问题描述
我想使用 API 在 github 上创建一个拉取请求。以下curl
命令确实有效
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" -H "Authorization: token ghp_abc...123" \
https://api.github.com/repos/alex4200/hello-world/pulls \
-d '{"head":"copyright_updater","base":"master","title":"Test PR curl"}'
但是这个python片段不起作用:
import requests
headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization": "token ghp_abc...123"
}
data = {
"head": "copyright_updater",
"base": "master",
"title": "Test PR python"
}
response = requests.post(
"https://api.github.com/repos/alex4200/hello-world/pulls",
headers=headers,
data=data
)
print(response.text)
此命令与 具有完全相同的数据curl
,返回 400 错误消息
{"message":"Problems parsing JSON","documentation_url":"https://docs.github.com/rest/reference/pulls#create-a-pull-request"}
这里有什么问题?
解决方案
推荐阅读
- c++ - 在 OpenMP 缩减中使用 Eigen Map
- django - Django POST 请求总是空的,但它不是
- delphi - 如何修改 Rad Studio 社区版
- kubernetes - 对于 pod 到 pod 的通信,应该使用什么 IP?服务的 ClusterIP 或端点
- sql - XP_CMDSHELL 不时无缘无故地被禁用
- c# - 在 vb.net 中使用 HttpWebRequest 代理
- spring - 基于 Spring Cloud 微服务与 Zuul 的 Spring CORS 过滤器问题
- reactjs - react-router 中的路由不匹配
- angular - Angular 5 想要从 ngx-bootstrap 模式获取价值到组件
- c# - 如何在 wix 安装程序的设置对话框中上传图像?