Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python wunderlist API任务中获取{“error”:“bad”request}_Python_Post_Python Requests_Wunderlist - Fatal编程技术网

在Python wunderlist API任务中获取{“error”:“bad”request}

在Python wunderlist API任务中获取{“error”:“bad”request},python,post,python-requests,wunderlist,Python,Post,Python Requests,Wunderlist,我想在python的wunderlist api中创建一个任务,下面是我的代码: import requests, json access_token = "MY TOKEN" client_id= "My Client ID" h = {"X-Access-Token": access_token, "X-Client-ID": client_id, "Content-Type": "application/json" da = {"list_ld": 330478059, "title":

我想在python的wunderlist api中创建一个任务,下面是我的代码:

import requests, json
access_token = "MY TOKEN"
client_id= "My Client ID"
h = {"X-Access-Token": access_token, "X-Client-ID": client_id, "Content-Type": "application/json"
da = {"list_ld": 330478059, "title": "TEST TASK"}
url= "https://a.wunderlist.com/api/v1/tasks"
r= requests.post(url, headers=h, data=da)

但是我收到了“坏请求”,为什么?

您发送的
da
中的数据需要进行JSONified。尝试将其转储到字符串-

from json import dumps
r = requests.post(url, headers=h, data=dumps(da))
或者,将
da
作为参数直接传递给
json=…
,这将自动处理序列化-

r = requests.post(url, headers=h, json=da)