我第一次使用Asana API。 我正在做的是使用python请求库将数据发布到asana-api
运行此curl命令时,它可以正常工作。
curl --request POST -H "Authorization: Bearer 12345678" https://app.asana.com/api/1.0/tasks/1234/addFollowers --data-urlencode "followers=191563290920498"
这可以按预期工作,但在使用此代码时,我收到错误
url = "https://app.asana.com/api/1.0/tasks/1234/addFollowers"
headers = {"Authorization":"Bearer 12345678"}
data = {"followers":[191563290920498]}
d =json.dumps(data)
response = requests.post(url,data = d ,headers= headers,verify = False)
错误是
{u'errors': [{u'message': u'Unrecognized request field `followers`. The only allowed keys at the top level are: data, options, auth. Is it possible you did not wrap object properties in a `data` object?', u'help': u'For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors'}]}
服务器响应为400,因此我传递数据的方式一定有问题。 我不知道我做错了什么。感谢任何帮助:)
我也试过这个实现: -
response = requests.post(url,params=d ,headers= headers,verify=False)
在这种情况下,错误消息是
{u'errors': [{u'message': u'Could not parse request data, invalid JSON', u'help': u'For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors'}]}
并且响应代码是< 400>