THE GAME HAS CHANGED

Introducing Infoblox Universal DDI ManagementTM

Watch the launch to discover the new era of management for critical network services. Watch Now

API & Integration, DevOps,NetOps,SecOps

Reply

Post Method works for Postman but Python

New Member
Posts: 4
6739     0

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'))

Re: Post Method works for Postman but Python

New Member
Posts: 4
6740     0

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.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You