Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

API Examples

Accepted Solution

Infoblox wapi python help with adding a new host to dns

[ Edited ]
Posts: 2
1005     0

I am trying to create a host if it does not exist and I am having trouble with the post command. Here is what I have so far:


# prompt user for credentials to infoblox
if sys.stdin.isatty():
print "Enter credentials to access infoblox"
username = raw_input("Username: ")
password = getpass.getpass("Password: ")
username = sys.stdin.readline().rstrip()
password = sys.stdin.readline().rstrip()

# creates session to infoblox
session = requests.Session()
session.auth = (username, password)
session.verify = False
url = infobloxURL 

# silence http warnings
ipAddress = ""
hostName = "zocalo"

# searches the internal DNS to see if host exists 
response = session.get(url + 'record:host?name~=^%s.mydomain.net$' % hostName)

# if there is a response, response.content will contain a json object with the properties for that host
hostExists = "%s.mydomain.net" % (hostName) in response.content

if hostExists == True:
print ("The hostname already exists in infoblox. Please select a new hostname and try again")
print("Success! The host does not exist in infoblox")

# add a host into infoblox
host = { "name":"%s.mydomain.net$" % hostName,
"ipv4addr":"%s" % ipAddress

response = session.post(url + 'record:host', data=host )

if response.status_code == 201:
print("successfully created a new host record in infoblox")
print("failure, host not added to infoblox")
print (response.status_code)
here is a copy of the output I am getting in the terminal when running my code:
Enter credentials to access infoblox
Username: xxxxx
Success! The host does not exist in infoblox
{ "Error": "AdmConProtoError: List value expected for field: ipv4addrs",
"code": "Client.Ibap.Proto",
"text": "List value expected for field: ipv4addrs"
while i am able to perform a get function to search for existing hosts, I am getting a status_code of 400 when I am trying to add a new host using post. Can someone with python and infoblox experience help me figure out what I am doing wrong?

Re: Infoblox wapi python help with adding a new host to dns

Posts: 138
1006     0



It seems to be an issue with the way you are passing the parameters.


This is a sample pythin script I use to create host records using Python.

import requests
requests.packages.urllib3.disable_warnings()  # Disable SSL warnings in requests #
url = "https://grid-master/wapi/v2.11/record:host?_return_as_object=1"
payload = "{\"name\":\"host.info.com\",\"ipv4addrs\": [{\"ipv4addr\":\"\"}]}"
headers = {'content-type': "application/json"}
response = requests.request("POST", url, auth=('admin', 'Infoblox'), data=payload, headers=headers, verify=False)

Hope this helpful,


Krishna Vasudevan


Re: Infoblox wapi python help with adding a new host to dns

Posts: 2
1006     0

Thanks I had figured out the problem but this is a good solution for anyone else who may come across this.


Re: Infoblox wapi python help with adding a new host to dns

Posts: 52
1006     0

Krishna, using this same methodology, can you post an example of searching for a host record, and then deleting it?


I can't seem to get the various commands (GET/POST/DELETE) to behave, and would appreciate seeing a common methodology.



Showing results for 
Search instead for 
Do you mean 

Recommended for You