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

Brand new to WAPI and Python. Trying to start with network view.

New Member
Posts: 2
2188     0

Trying to start using WAPI with python, but I'm having a hard time trying to just get a network view. 

 

I'm trying to run a requests to my grid master MGMT IP. 

 

import requests
import json
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


session = requests.Session()
session.auth = ('USERNAME', 'PASSWORD')
session.verify = False
url = 'https://10.210.XX.XXX/wapi/v2.11.3/'
headers = {'Content-type' 'application/json'}

r = session.get(url + 'network')
print(r)

 

But I get a reponse 400 so I don't know what I need to fix here.  

 

Then I figured out how to install infoblox_client on my windows computer and tried running this script to get the network view. But this then gives me a invalid username and password.  These credentials work on the GUI so I don't know why it is failing. The user has superuser access and also API access. I'm a stump and don't know what to do. 

 

from infoblox_client import connector

opts = {'host': '10.210.188.48', 'username': 'USERNAME', 'password': 'PASSWORD'}
conn = connector.Connector(opts)
# get all network_views
network_views = conn.get_object('networkview')


print(network_views)

 

 

Re: Brand new to WAPI and Python. Trying to start with network view.

Moderator
Moderator
Posts: 315
2189     0

For infoblox-client, try using exceptions, to help with troubleshooting.  And adjust to match your WAPI version.

 

This works:

 

from infoblox_client import connector, exceptions

network_views = {}

try:
    conn = connector.Connector({
        'host': '10.210.188.48',
        'username': 'admin',
        'password': 'infoblox',
        'wapi_version': '2.10'
    })

    network_views = conn.get_object('networkview')

except exceptions.InfobloxBadWAPICredential as e:
    logger.error(e)
    sys.exit(255)
except exceptions.InfobloxConfigException as e:
    logger.error(e)
    sys.exit(255)

print(network_views)

It returns:

 

[{'_ref': 'networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true', 'is_default': True, 'name': 'default'}]



 

Re: Brand new to WAPI and Python. Trying to start with network view.

Moderator
Moderator
Posts: 315
2189     0

For the "requests" type, try this:

 

import requests
import json
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

session = requests.Session()

url = 'https://10.210.188.48/wapi/v2.11.3/'
headers = {'Content-type': 'application/json'}
auth = ('admin', 'infoblox')
r = session.get(url + 'network', auth=auth, headers=headers, verify=False)

response = r.json()

print(response)
Showing results for 
Search instead for 
Did you mean: 

Recommended for You