将cURL转换为Python:使用额外参数
我正在尝试使用正确授权发出API请求。我查看了,但在放置授权标题时遇到问题 这就是我到目前为止所做的:将cURL转换为Python:使用额外参数,python,curl,Python,Curl,我正在尝试使用正确授权发出API请求。我查看了,但在放置授权标题时遇到问题 这就是我到目前为止所做的: import base64 import http.client import requests import json headers = { "Content-Type": "application/json", 'Authorization': 'Basic %s' % base64.b64encode(b'username:password').dec
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"]}'
感谢您的帮助。您遇到了什么错误TypeError:memoryview:需要一个类似字节的对象,而不是'str'。请不要将有效负载转换为字符串,将其作为python对象保留。我很抱歉,但您能澄清一下吗?