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

2k views Asked by At

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)
1

There are 1 answers

0
DorElias On BEST ANSWER

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)