Requests - HTTP DELETE Method - Python Examples
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('/')
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('/')
print(response.headers)
{'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': '</wp-json/>; rel="https://api.w.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.