Requesting the HTTP GET REST API via Python

In this example, we will perform an HTTP GET REST API request via Python:

  1. Open a text editor, input the following code and save it into the .py extension, for example NSX-PythonGET.py:
# Import Requests library import requests # NSX Variables nsxmanager = 'https://nsxmgr-01a.corp.local' nsxurl = '/api/2.0/services/usermgmt/user/admin' nsxheaders = {'Content-Type': 'application/xml'} nsxuser = 'admin' nsxpass = 'VMware1!' # REST API call using requests.get function from request library. Set verify to False to ignore SSL response = requests.get(nsxmanager + nsxurl, auth = (nsxuser, nsxpass), verify = False, headers = nsxheaders) # Print HTTP Response Code print (response) # Print XML Content print ...

Get VMware NSX Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.