0

I have use curl in linux to post data to asana and its work fine.

curl -H "Authorization: Bearer <mytoken>" https://app.asana.com/api/1.0/tasks/101/stories -d "text=hello world"

but if I use requests library for python the result is 400

response = requests.post("https://app.asana.com/api/1.0/tasks/101/stories", auth=(self.asana.token_uri, ""), params = "text=repo_name")
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

2 Answers2

0

You need to add the same "Authorization: Bearer" token header to your request in python. Similar to this answer:

https://stackoverflow.com/a/29931730/6080374

Community
  • 1
  • 1
0

The auth argument to requests methods produces a Authorization: Basic header, not a Authorization: Bearer header.

Set a headers dictionary with a manually created Authorization header instead. POST data (the -d command line switch for curl) should be passed as a dictionary to the data argument:

response = requests.post(
    "https://app.asana.com/api/1.0/tasks/101/stories",
    headers={'Authorization': 'Bearer {}'.format(self.asana.token_uri),
    data={'text': 'repo_name'})
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343