Python Requests – HTTP DELETE

HTTP DELETE Request

HTTP DELETE request is used to delete a resource in a specified server.

Example

In Python Requests library, requests.delete() method is used to send a DELETE request to specified server over HTTP.

import requests

response = requests.delete('https://pythonexamples.org/')
Run Code Copy

requests.delete() returns a Response object. It contains all the data and properties like response content, headers, encoding, cookies, etc. Let us print out headers.

import requests

response = requests.delete('https://pythonexamples.org/')
print(response.headers)
Run Code Copy
{'Date': 'Mon, 25 Mar 2019 14:15:42 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Content-Length': '12139', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=30', 'Server': 'Apache/2', 'X-Powered-By': 'PHP/5.6.30', 'Link': '<https://pythonexamples.org/wp-json/>; rel="https://api.w.org/", <https://pythonexamples.org/>; rel=shortlink', 'Vary': 'Accept-Encoding', 'Content-Encoding': 'gzip', 'Referrer-Policy': 'no-referrer-when-downgrade'}

Summary

In this Python Tutorial, we learned about HTTP DELETE request in requests module.

Related Tutorials

Code copied to clipboard successfully 👍