Hi all,
I have to use a Proxy to get Access to Azure with Python.
I'm not able to get it working using Environment variables, is it also possible in another way?
This works for me:
import requests
proxies = {
'https': 'https://10.64.3.193:8080',
}
print(requests.get('https://example.org', proxies=proxies))
Also looked at this for reference:
http://docs.python-requests.org/en/master/user/advanced/#proxies
Hi,
All Python SDK in the Azure eco-system uses requests, and I know people were using env var successfully, you should be able to rewrite your previous example with env variable. And if it works, will work for any SDKs.
Also, if using one of the SDK in this repo, you can do:
client.config.proxies.add("https", 'https://10.64.3.193:8080')
If you use credentials classes like ServicePrincipalCredentials, you can pass proxies while creating:
ServicePrincipalCredentials(
client_id,
secret,
tenant=tenant_id,
proxies=proxies
)
If you get your token using ADAL or another libraries, please use their documentation.
Hi lmazuel,
Thanks for the help, I got it working by setting the proxy as system variable.
Kind regards,
Steven
Hi @StevenKoppens and @lmazuel,
I know this issue is closed but I want to clarify something with you guys. I also need to use a proxy to authenticate using a service principal in Azure. But the problem is, if a set the proxy on the script, using azure.identity SDK for python, the script won't work and won't authenticate. The only way I got it working was setting the environment variables HTTP_PROXY and HTTPS_PROXY using a SET command on windows before I run the script. This behavior could be a bug in the azure.identity SDK? Do you guys have any idea why I won't be able to authenticate when setting the proxy on the script?
The code I was using is as follows:
```python
from azure.identity import ClientSecretCredential
from azure.storage.blob import ContainerClient
account_name = '******'
client_id = '******'
tenant_id = '******'
client_secret = '******'
container_name = '*'
print(1)
http_proxy = 'http://ip:port'
https_proxy = 'https://user:password@ip:port/'
proxies = {
'http': http_proxy,
'https': https_proxy
}
print(2)
credential = ClientSecretCredential(tenant_id, client_id, client_secret, proxies=proxies)
print(3)
container = ContainerClient(account_url="https://"+account_name+".blob.core.windows.net/", container_name=container_name, credential=credential, proxies=proxies)
print(4)
blob_list = container.list_blobs()
print(5)
for blob in blob_list:
print(blob.name + 'n')
print(6)
```
This code authenticate to Azure using a service principal and them list the files in a blob container.
When I run the code above it hangs after print(4).
Am I using the SDK correctly to set the proxy? Do you guys have any tip?
Thank you very much.
@nascimentocrafael before opening a new issue, could you do before "print(3)":
credential.get_token("https://storage.azure.com/.default")
If it hangs there, please create an issue focused on ClientSecretCredential and don't even mention Storage (that would mean an identity issue).
If this line pass, please create an issue focused on Storage, explaining the test I just asked you to do to confirm it's not identity bug.
Thanks!
Most helpful comment
Hi lmazuel,
Thanks for the help, I got it working by setting the proxy as system variable.
Kind regards,
Steven