- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Retrieving Network Details using Python webAPI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2016 01:45 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2017 01:07 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2017 10:04 AM
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()
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2018 04:27 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2018 04:29 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2018 05:36 AM
Cant this be done with iblox library?
Re: Retrieving Network Details using Python webAPI
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2018 04:42 AM - edited 12-10-2018 03:47 AM
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
Re: Retrieving Network Details using Python webAPI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2018 06:22 AM
Also take a look at https://github.com/infobloxopen/infoblox-client