- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Post Method works for Postman but Python
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2020 02:05 PM
Hello,
I coud achieve post requests via Postman when i try in python code which gives below error. I read its because of role, i added new user with api permission , even previous user works with Postman but didnt work.
b'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>401 Authorization Required</title>\n</head><body>\n<h1>Authorization Required</h1>\n<p>This server could not verify that you\nare authorized to access the document\nrequested. Either you supplied the wrong\ncredentials (e.g., bad password), or your\nbrowser doesn\'t understand how to supply\nthe credentials required.</p>\n</body></html>\n'
My Code:
import requests
url = "https://10.10.10.10/wapi/v2.7/network"
payload = "{\"network\":\r\n\"func:nextavailablenetwork:10.10.8.0/21,default,28\",\r\n\"comment\":\"Test\",\r\n\"network_view\":\"default\"\r\n}"
headers = {
'Content-Type': 'application/json',
'Cookie': 'ibapauth="group=admin-group,ctime=1591971023,ip=10.10.10.2,auth=LOCAL,client=API,su=1,timeout=1800,mtime=1591971692,user=apiuser,apipassword"'
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
Solved! Go to Solution.
Re: Post Method works for Postman but Python
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2020 03:01 AM
This method worked for me .
r = requests.post(url ,payload,
auth=("user", "password"),
verify=False)
After that i should contione with cookie (r.cookies).
Thank you.