[英]How not to let python requests calculate content-length and use the provided one?
[英]Python requests, how to calculate Content-Length and add host to convert request from Postman
自由使用请求我想将我的 POST 请求从 Postman 转换为 Python function。我当前的代码返回“('发票必须采用 xml 格式',400)”。 如果我应该添加以下键,我不支持:Content-Length 和 Host。 如果是,如何计算header中的这些值?
Postman 次请求
我的 Python 密码
import requests
url3 = 'http://xxx.azure.com/xxx/api/file'
file = 'ok/test_file.xml'
headers = {'Token': 'xxx',
'Content-Type': 'application/xml'}
body = {'Tags': 'python',
'ExternalTrackingId': '1-python',
'FastTrack': False,
'RequiresBatchSend': True,
'file.xml': (open(file, 'rb'), 'text/xml')}
def send_invoice():
send_file = requests.post(url3, headers=headers, data=body)
return send_file.text, send_file.status_code
print(send_invoice())
回复
('File must be in xml format', 400)
如何改进我的代码以将 XML 文件正确发送到 API?
在 postman 中,您可以检查您的请求并阅读几乎所有语言的代码请求,包括 python 请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.