如何使用请求库执行HTTP DELETE请求 [英] How to do a HTTP DELETE request with Requests library
本文介绍了如何使用请求库执行HTTP DELETE请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用请求程序包与之交互toggl.com API。
I'm using the requests package for interacting with the toggl.com API.
我可以执行GET和POST请求:
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?
推荐答案
使用 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')
)
这篇关于如何使用请求库执行HTTP DELETE请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文