pythonazureproxy

How to set session proxy in Azure Python SDK for NetworkManagementClient?


I want to be able to use a proxy server with Azure Python SDK NetworkManagementClient (NMC). I saw that the NMC has a _client attribute of type msrest.service_client, which includes a config attribute of type NetworkManagementClientConfiguration which inherits from AzureConfiguration, which itself has a proxies attribute of type msrest.pipeline.ClientProxies.

Given the above it seems that configuring a proxy is possible, but I don't understand the proper way to set it up.


Solution

  • First, msrest is using requests, so I assume you read proxies documentation of requests. Note too that a requests.Session object has a trust_env attribute that is True by default to read some env variables like HTTP_PROXY.

    The configuration of a client has a proxies attribute, being as you mentioned a ClientProxies class. This class has a proxies dict attribute itself and a add method to add in this dict. This class has also a use_env_settings boolean attribute.

    Assuming you have a client variable instance of NetworkManagementClient, so you can either:

    (I own msrest at MS)