2012-04-17 51 views
18

Tôi đang sử dụng gói requests để tương tác với API toggl.com.Cách thực hiện yêu cầu DELETE HTTP với thư viện Yêu cầu

tôi có thể thực hiện GET và POST yêu cầu:

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')) 

nhưng tôi không thể dường như để tìm một cách để thực hiện một yêu cầu DELETE. Điều này có khả thi không?

Trả lời

34

Sử dụng requests.delete thay vì 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'))