我试图curl
在 python 请求中转换这个命令,但我不确定我应该如何传递数据:
curl -X POST -u "apikey:{apikey}" \
--header "Content-Type: text/plain" \
--data "some plain text data" \
"{url}"
Run Code Online (Sandbox Code Playgroud)
我试图直接传递字符串并对其进行编码,str.encode('utf-8')
但出现错误 415Unsupported Media Type
这是我的代码:
text = "some random text"
resp = requests.post(url, data=text, headers={'Content-Type': 'text/plain'}, auth=('apikey', self.apikey))
Run Code Online (Sandbox Code Playgroud)
[编辑]:解决方案是不在请求中指定标头
非常感谢!