pythonpython-requestshttp-deletecontent-lengthhttp-content-length

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)

Solution

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