0

I can do this Curl:

curl -X POST -k --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"grant_type":"password","username":"admin","password":"admin"}' 'https://<ip_address>/api/fdm/v3/fdm/token'

and get an access token from the firewall API I'm working on. But I'm trying to get it to work in Python using requests:

headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}

payload = {
"grant_type": "password",
"username": "admin",
"password": "admin"
}

r = requests.post('https://<ip_address>/api/fdm/v3/fdm/token', headers=headers, data=payload, verify=False)

and I get a 401 Unauthorized. I also tried converting my payload to json and doing json=payload in my requests.post but get the same results. What am I doing wrong? Does curl send some default header info I'm not including in my requests? Thanks!

1 Answer 1

2

You need to use the json parameter to requests.post. What you are doing there is sending a form data request.

Something like:

r = requests.post('https://<ip_address>/api/fdm/v3/fdm/token', headers=headers, json=payload, verify=False)
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.