0

This curl command works:

curl -X GET 172.168.0.101/api/v1/events/ -H 'Authorization: Token 353e5axxxxxxxxxxxxxxxxxxxxx'

I want to do the same in python and requests seems like a good lib.

However:

import requests

header = {'Authorization': 'Token 353e5axxxxxxxxxxxxxxxxxxxxx'}
r = requests.post('http://172.168.0.101/api/v1/events/', headers=header)
print r

does not work. It results in a 400 response.

1
  • 1
    I've never used Python requests before, but it seems that with curl you are doing a GET, but with Python requests you are doing a POST. Commented Sep 25, 2014 at 22:33

1 Answer 1

2

Use requests.get() instead:

r = requests.get('http://172.168.0.101/api/v1/events/', headers=header)

The post method you used sends a POST request, while your curl command line clearly uses GET instead. The 400 error returned indicates POST is the wrong method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.