Skip to main content

Just posting up a simple Python script that allows you to make API calls from behind a proxy that also requires authentication.

I have capitalised things that you need to customise.ย  Of course it isnโ€™t good practice to have usernames and passwords in your script so this is just for illustrative purposes.

import requests
import base64

api_user = "YourApiUser"
api_pass = "YourApiPassword"
api_creds = api_user + ":" + api_pass


api_bytes = api_creds.encode("ascii")
api_encoded = base64.b64encode(api_bytes)
print(api_encoded)
api_string = api_encoded.decode("ascii")

proxies = {
"http": "http://YourProxyUser:YourProxyPassword@ProxyServerIp:ProxyPort",
"https": http://YourProxyUser:YourProxyPassword@ProxyServerIp:ProxyPort",
}

try:
response = requests.get("https://fwd.app/api/networks", proxies=proxies, headers={"Authorization" : "Basic " + api_string})
print(response.json())
except requests.exceptions.ProxyError as e:
print("Proxy error:", e)

ย 

Be the first to reply!