Open In App
Related Articles

DELETE method- Python requests

Like Article
Save Article
Report issue
Requests library is one of the important aspects of Python for making HTTP requests to a specified URL. This article revolves around how one can make DELETE request to a specified URL using requests.delete() method. Before checking out the DELETE method, let’s figure out what a Http DELETE request is –

DELETE Http Method

DELETE is a request method supported by HTTP used by the World Wide Web. The DELETE method deletes the specified resource. As with a PUT request, you need to specify a particular resource for this operation. A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity. An example URI looks like for delete operation

How to make DELETE request through Python Requests

Python’s requests module provides in-built method called delete() for making a DELETE request to a specified URI. Syntax –
requests.delete(url, params={key: value}, args)
Example – Let’s try making a request to httpbin’s APIs for example purposes.
import requests
# Making a DELETE request
r = requests.delete(' / delete', data ={'key':'value'})
# check status code for response received
# success code - 200
# print content of request

save this file as and through terminal run,
Output – delete-method-python-requests

Advanced with DELETE request

The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.

Last Updated : 26 Feb, 2020
Like Article
Save Article
Share your thoughts in the comments
Similar Reads