我想在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)
但我得到" bad_request",为什么?
答案 0 :(得分:1)
您发送的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)
会自动处理序列化 -
<html>
<head>
<style>
.section {
clear: both;
padding: 0px;
margin: -5px;
font-size: 0;
}
.col {
font-size: 16px;
float: left;
margin: 5px;
width: calc( 33.33% - 10px);
}
.group {
width: 100%;
}
.group:after {
clear: both;
}
.group {
zoom: 1;
/* For IE 6/7 */
}
@media only screen and (max-width: 500px) {
.col {
width: calc( 50% - 10px);
}
}
@media only screen and (max-width: 300px) {
.col {
width: 100%;
}
}
</style>
</head>
<body>
<div class="section group">
<div class="col">
This is column 1
</div>
<div class="col">
This is column 2
</div>
<div class="col">
This is column 3
</div>
</div>
</body>
</html>