How to configure proxies for the Azure libraries

A proxy server URL has of the form http[s]://[username:password@]<ip_address_or_domain>:<port>/ where the username:password combination is optional.

You can then configure a proxy globally by using environment variables, or you can specify a proxy by passing an argument named proxies to an individual client constructor or operation method.

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 any version of the Azure libraries.

These environment variables are ignored if you pass the parameter use_env_settings=False to a client object constructor or operation method.

From Python code

import os
os.environ["HTTP_PROXY"] = ""

# Alternate URL and variable forms:
# os.environ["HTTP_PROXY"] = "http://username:password@"
# os.environ["HTTPS_PROXY"] = ""
# os.environ["HTTPS_PROXY"] = "http://username:password@"

From the CLI

rem Non-authenticated HTTP server:

rem Authenticated HTTP server:
set HTTP_PROXY=http://username:password@

rem Non-authenticated HTTPS server:

rem Authenticated HTTPS server:
set HTTPS_PROXY=http://username:password@

Per-client or per-method configuration

To configure a proxy for a specific client object or operation method, specify a proxy server with an argument named proxies.

For example, the following code from the article Example: use Azure storage specifies an HTTPS proxy with user credentials with the BlobClient constructor. In this case, the object comes from the library, which is based on azure.core.

from azure.identity import DefaultAzureCredential

# Import the client object from the SDK library
from import BlobClient

credential = DefaultAzureCredential()

storage_url = "your_url"

blob_client = BlobClient(storage_url, container_name="blob-container-01",
    blob_name="sample-blob.txt", credential=credential,
    proxies={ "https": "https://username:password@" }

# Other forms that the proxy URL might take:
# proxies={ "http": "" }
# proxies={ "http": "http://username:password@" }
# proxies={ "https": "" }