Python Requests – HTTP DELETE – Example

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

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 this program

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 this program
{'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'}