Example Python script
The following Python script demonstrates similar tests to the ones described in the previous section. This is written for the CSV API but would be equally valid for the XML API.
import urllib def runQuery(): # Successful output query = "http://appliance/ui/api/CsvApi?query=SEARCH%20Host&username=apiuser&password=password" f = urllib.urlopen(query) print f.read() # Empty query - output will be 1. query1 = "http://appliance/ui/api/CsvApi?username=apiuser&password=password" f = urllib.urlopen(query1) print f.read() # Invalid query - output will be 3. query3 = "http://appliance/ui/api/CsvApi?query=SEARCHX%20Host&username=apiuser&password=password" f = urllib.urlopen(query3) print f.read() # Authorisation failure - Output server code of 401. query4 = "http://appliance/ui/api/CsvApi?query=SEARCH%20Host&username=apiuser&password=wrongpassword" f = urllib.urlopen(query4) print f.read() if __name__ == '__main__': runQuery()
Note
With no exception handler around Query4, a 401 Unauthorised IOError traceback is produced.
Was this page helpful? Yes No
Submitting...
Thank you
Comments
Log in or register to comment.