Python requests remove the Content-Length header from POST

感情迁移 提交于 2019-11-29 02:30:00

You'll have to prepare the request manually, then remove the generated content-length header:

from requests import Request, Session

s = Session()
req = Request('POST', url, data=data)
prepped = req.prepare()
del prepped.headers['content-length']
response = s.send(prepped)

Do note that most compliant HTTP servers may then ignore your post body!

If you meant to use chunked transfer encoding (where you don't have to send a content length), then use a iterator for the data parameter. See Chunked-Encoded Requests in the documentation. No Content-Length header will be set in that case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!