38

我正在使用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'))

但我似乎找不到执行删除请求的方法。这可能吗?

4

2 回答 2

76

使用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')
)
于 2012-04-17T13:02:00.283 回答
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
于 2018-09-13T07:38:18.013 回答