Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a HTTP DELETE request with Requests library

I'm using the requests package for interacting with the toggl.com API.

I can perform GET and POST requests:

    payload = {'some':'data'}     headers = {'content-type': 'application/json'}     url = "https://www.toggl.com/api/v6/" + data_description + ".json"     response = requests.post(url, data=json.dumps(payload), headers=headers,auth=HTTPBasicAuth(toggl_token, 'api_token')) 

but i cant seem to find a way to perform a DELETE request. Is this possible?

like image 472
jorrebor Avatar asked Apr 17 '12 12:04

jorrebor


People also ask

How do I make a http request delete?

An example of sending an HTTP DELETE request to the server. The Accept: */* request header tells the server that the client can accept any type of media in the server's response. In this HTTP DELETE request example, we are sending a DELETE request to the ReqBin echo URL.

How do you send a delete request in Python?

The delete() method sends a DELETE request to the specified url. DELETE requests are made for deleting the specified resource (file, record etc).

Can we use request body with delete?

This is an know scenario and Integration Server doesn't accept request body for HTTP DELETE Method. The only means to accept the content for DELETE method in IS is by passing the Query parameter.

Which method performs at HTTP delete?

The DELETE method deletes the specified resource. The CONNECT method establishes a tunnel to the server identified by the target resource. The OPTIONS method describes the communication options for the target resource. The TRACE method performs a message loop-back test along the path to the target resource.


1 Answers

Use requests.delete instead of requests.post

payload = {'some':'data'} headers = {'content-type': 'application/json'} url = "https://www.toggl.com/api/v6/" + data_description + ".json"  response = requests.delete(     url,      data=json.dumps(payload),      headers=headers,     auth=HTTPBasicAuth(toggl_token, 'api_token') ) 
like image 108
Elvis D'Souza Avatar answered Sep 19 '22 15:09

Elvis D'Souza