简体   繁体   中英

How to do a HTTP DELETE request with Python requests module without “Content-Length: 0”?

I am doing a HTTP DELETE with Python requests module, but I am facing a problem in my application because of the "Content-Length: 0". Is there a way to deal with this? Is possible to remove the "Content-Length: 0"? What do you suggest?

The problem is that the server application does not accept "Content-Length", neither payload. This way, my request should not have this information.

The request I am doing:

headers = {'X-Auth-Token': token}
r = requests.delete(DELETE_URL, headers=headers)

Well you can remove the header manually like in here

example:

from requests import Request, Session

s = Session()

req = Request('DELETE', url)
prepped = req.prepare()
del prepped.headers['Content-Length']
resp = s.send(prepped)
print(resp.status_code)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM