python - 将 cURL 转换为 Python:使用额外的参数
问题描述
我正在尝试通过适当的授权发出 API 请求。我查看了将 curl 转换为 python 请求,但在放置授权标头时遇到了麻烦。
这是我到目前为止所拥有的:
import base64
import http.client
import requests
import json
headers = {
"Content-Type": "application/json",
'Authorization': 'Basic %s' % base64.b64encode(b'username:password').decode('ascii'),
}
payload = {json.dumps({"one":["two:three:four"]})}
url = 'https://website/v1'
r = requests.post(url, data=payload, headers=headers)
if __name__=='__main__':
print (r.text)
上面提供的链接和我的代码之间的唯一区别是他有query={"tags":["test1","test2"]}
我根本没有。
这是我试图翻译的卷曲以获得上面的内容。
curl -X POST -u "username:password" -H "Content-Type:application/json" "https://website.com" -d '{"ids":["something:numberOne:numbertwo"]}'
任何帮助表示赞赏。
解决方案
推荐阅读
- c# - 用于输入的 C# WPF 动态名称
- android - 将数据从 recylerview 适配器传递到导航抽屉中的片段
- mysql - 只进行一次查询即可从同一张表中获取数据
- jenkins - Groovy:构造函数调用必须是构造函数中的第一条语句
- vue.js - VueJS 生产模式是否删除所有警告
- python - 在 PyQt5 中设置 QComboBox 中项目的图标大小
- image-processing - 如何在二进制高分辨率分割中下采样输入标签?
- javascript - 如何链接 onclick 回调以调用外部文件
- sql - 在我的第一个存储过程结束后如何启动存储过程?
- plc - Metasploit 模块 NoMethodError 未定义方法 'get_once' 用于 nil:NilClass