Reply

Retrieving Network Details using Python webAPI

Posts: 10
22548     0

Hi,

 

I'm writting a python webAPI to find out the Network Details of a  given network.I want script to give me the details of the network passed though commnad line. My problem is how do I susbtitute the variable 'ip' in Python formate to form a correct request.

 

it works fine when I hard code the network value

Here is my code (functional)

 

r = requests.get(url + 'network?network=00.00.00.00/00',
auth=(id,pw),
verify=True);

 

Non functional:

ip = raw_input("Please enter the network\n");
print(ip)

r = requests.get(url + "network?network= %s" ip,
auth=(id,pw),
verify=True);

 

New to python, please advise.

Nidhi Srivastava

Re: Retrieving Network Details using Python webAPI

Adviser
Posts: 11
22548     0

Hi Nidhi,

 

This worked for me.

 

Code:

________________________________________________________________

#!/usr/bin/python
import requests
from requests.auth import HTTPBasicAuth
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


requestobject = raw_input("Enter network: ")
url = "https://10.192.32.240/wapi/v2.5/network?network="
user = "admin"
password = "infoblox"
response = requests.get(url+requestobject,auth=HTTPBasicAuth(user,password), verify = False)
print response.text

 

________________________________________________________________

 

 

Regards,

Sandeep

 

 

 

 

 

 

Re: Retrieving Network Details using Python webAPI

New Member
Posts: 1
22548     0

Hello all,

 

I tried following the instructions to get some data from a subnet within my environment and I am getting the following errors:

 

A snipped of my code

 

import requests

import argparse

from requests.auth import HTTPBasicAuth

from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

from getpass import getpass

parser = argparse.ArgumentParser(description='API to interact with infoblox.')

parser.add_argument("-subnet", action="store", dest="subnet", type=str, help="Next available IP in subnet")

args = parser.parse_args()

url = "https://x.x.x.x/wapi/v2.6/network/ZG5zLm5ldHdvcmskMTA1LjE0OC4xNTQuMC8yNC8w:{}/24/default-NetworkView...)

if args.subnet:

   querystring = {"_function":"next_available_ip","_return_as_object":"1"}

   requests.packages.urllib3.disable_warnings()

   response = requests.request("POST", url, auth=HTTPBasicAuth(input("username: "), getpass()), verify=False, params=querystring)

   print(response.text)

 

 

I am getting SSL errors (<big>Untrusted SSL Server Certificate (ssl_server_cert_untrusted_issuer)</big>) – I have downloaded the root cert and used that in the request as well and it did not work.

 

Errors:

 

Password:

<HTML><HEAD>

<TITLE>Untrusted SSL Server Certificate</TITLE>

</HEAD>

<BODY>

<FONT face="Helvetica">

<big><strong></strong></big><BR>

</FONT>

<blockquote>

<TABLE border=0 cellPadding=1 width="80%">

<TR><TD>

<FONT face="Helvetica">

<big>Untrusted SSL Server Certificate (ssl_server_cert_untrusted_issuer)</big>

<BR>

<BR>

</FONT>

</TD></TR>

<TR><TD>

<FONT face="Helvetica">

Your request contacted a host which presented a certificate signed by an untrusted issuer.

</FONT>

</TD></TR>

<TR><TD>

<FONT face="Helvetica">

This is typically caused by a Web Site presenting an incorrect or invalid certificate, but could be because of a configuration error.

</FONT>

</TD></TR>

<TR><TD>

<FONT face="Helvetica" SIZE=2>

<BR>

For assistance, contact your network support team.

</FONT>

</TD></TR>

</TABLE>

</blockquote>

</FONT>

</BODY></HTML>

 

I need help with getting this information so that I can finish writing my script.

 

Can support also help here? If yes, I will open a support case

Re: Retrieving Network Details using Python webAPI

Adviser
Posts: 11
22548     0

Hi Nidhi,

 

Could you try using "r = requests.get(url + "network?network="+ip"  rather than "r = requests.get(url + "network?network= %s" ip".

 

 

Please keep in mind that the user input for network has to be in the format <network/cidr> .

 

Regards,

Sandeep

 

 

Re: Retrieving Network Details using Python webAPI

Adviser
Posts: 11
22548     0

Hi Nidhi,

 

Could you try using "r = requests.get(url + "network?network="+ip"  rather than "r = requests.get(url + "network?network= %s" ip".

 

 

Please keep in mind that the user input for network has to be in the format <network/cidr >.

 

Regards,

Sandeep

Re: Retrieving Network Details using Python webAPI

New Member
Posts: 1
22548     0

Cant this be done with iblox library?

Re: Retrieving Network Details using Python webAPI

[ Edited ]
New Member
Posts: 1
22548     0

Hai Nidhi,

Thanks for sharing the code. It works for me. I got the all details what i want. As i am the python Developer, I am not having the idea. 

 

Thanks for sharing nice information.

 

 

Regards,

Riya

Having 3 Years of Experience as a software Developer at Tekslate.com

Re: Retrieving Network Details using Python webAPI

Authority
Posts: 11
22548     0
Showing results for 
Search instead for 
Did you mean: 

Recommended for You