Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You often need a proxy if:
- You're behind a corporate firewall.
- Your network traffic needs to go through a security appliance.
- You want to use a custom proxy for debugging or routing.
If your organization requires a proxy server to access internet resources, set an environment variable with the proxy server information before you use the Azure SDK for Python. When you set the HTTP_PROXY and HTTPS_PROXY environment variables, the Azure SDK for Python uses the proxy server at run time.
A proxy server URL has the form http[s]://[username:password@]<ip_address_or_domain>:<port>/, where the username and password combination is optional.
You can obtain your proxy information from your IT or network team, from your browser, or from network utilities.
You can configure a proxy globally by using environment variables. You can also configure a proxy for an individual client constructor or operation method by passing an argument named proxies.
Global configuration
To configure a proxy globally for your script or app, define HTTP_PROXY or HTTPS_PROXY environment variables with the server URL. These variables work with any version of the Azure libraries. Note that HTTPS_PROXY doesn't mean an HTTPS proxy. It specifies the proxy to use for https:// requests.
If you pass the parameter use_env_settings=False to a client object constructor or operation method, the SDK ignores these environment variables.
Set from the command line
rem Non-authenticated HTTP server:
set HTTP_PROXY=http://10.10.1.10:1180
rem Authenticated HTTP server:
set HTTP_PROXY=http://username:password@10.10.1.10:1180
rem Non-authenticated HTTPS server:
set HTTPS_PROXY=http://10.10.1.10:1180
rem Authenticated HTTPS server:
set HTTPS_PROXY=http://username:password@10.10.1.10:1180
Set in Python code
Set proxy settings by using environment variables. You don't need any custom configuration.
import os
os.environ["HTTP_PROXY"] = "http://10.10.1.10:1180"
# Alternate URL and variable forms:
# os.environ["HTTP_PROXY"] = "http://username:password@10.10.1.10:1180"
# os.environ["HTTPS_PROXY"] = "http://10.10.1.10:1180"
# os.environ["HTTPS_PROXY"] = "http://username:password@10.10.1.10:1180"
Custom configuration
Set a proxy in Python code for a client or method
For custom configuration, specify a proxy for a specific client object or operation method. Use an argument named proxies.
For example, the following code from the article Example: use Azure storage specifies an HTTPS proxy with user credentials in the BlobClient constructor. In this case, the object comes from the azure.storage.blob library, which is based on azure.core.
from azure.identity import DefaultAzureCredential
# Import the client object from the SDK library
from azure.storage.blob import BlobClient
credential = DefaultAzureCredential()
storage_url = "https://<storageaccountname>.blob.core.windows.net"
blob_client = BlobClient(storage_url, container_name="blob-container-01",
blob_name="sample-blob.txt", credential=credential,
proxies={ "https": "https://username:password@10.10.1.10:1180" }
)
# Other forms that the proxy URL might take:
# proxies={ "http": "http://10.10.1.10:1180" }
# proxies={ "http": "http://username:password@10.10.1.10:1180" }
# proxies={ "https": "https://10.10.1.10:1180" }