I am using Python request module post method to process json data, like so.
r = requests.post(url,data=json.dumps(payload),headers=headers)
However I am getting response[401]
. Does it mean I need to first authorize it
by adding login first?
A 401
response, as you noticed, means that you need to authenticate in order to make the request. How you do this depends on the auth system in place, but your comment "I use HTTPBasicAuth(user, password) that give me response code of 200" suggests that it's just Basic Auth - which is easy to deal with in requests
.
Anywhere you do a requests
call, add the kwarg auth=(USERNAME, PASSWORD)
- so for your example above, you'd do r = requests.post(url,data=json.dumps(payload),headers=headers, auth=(USERNAME, PASSWORD))
(replacing USERNAME and PASSWORD with the right values, as shown here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With