Using Python with Proxy and Authentication

I was configuring proxy in command prompt by using:

set https_proxy=http://USERNAME:PASSWORD@PROXYFQDN:PORT

Then running Python. But you can also put the proxy with authentication configuration into your Python command line or Python scripts like:

import requests
proxies = {'https': 'http://USERNAME:PASSWORD@PROXYFQDN:PORT'}

And then to use the proxies, you just add it into your request, for example (with NetApp Cloud Insights and getting the names of all dwh_custom tables):

import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

proxies = {'https': 'http://USERNAME:PASSWORD@PROXYFQDN:PORT'}
yourTenant = "YOURTENANT"
apiKey = "APIKEY"
headers = {'X-CloudInsights-ApiKey': '{key}'.format(key=apiKey)}

api = "rest/v1/dwh-management/odata/dwh_custom"
j = requests.get(yourTenant + api,header=headers,proxies=proxies,verify=False).json()

for row in j['value']: print(row['name'])

Comments