我正在使用requests包与toggl.com API进行交互。
我可以执行GET和POST请求:
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'))
但我似乎无法找到执行DELETE请求的方法。 这可能吗?
答案 0 :(得分:48)
使用requests.delete代替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'))
答案 1 :(得分:0)
import requests
url = 'url.example.ap'
headers = {
'content-type': "multipart/form-data; boundary=---- ",
'X-Auth-Token': ""anytoken"",
'Cache-Control': "no-cache"
}
r = requests.delete(url, headers=headers)
n = os.write(sys.stdout.fileno(), r.content)
print r.content == r.text