Azure / azure-cli

Azure Command-Line Interface
MIT License
3.92k stars 2.89k forks source link

ERROR: <urllib3.connection.HTTPSConnection object at 0x7ff24b791100>: Failed to establish a new connection: [Errno -2] Name or service not known #27315

Open anilsakr opened 10 months ago

anilsakr commented 10 months ago

Describe the bug

I'm encountering a connectivity issue when trying to run the following Azure CLI command in our QA environment: az storage blob upload-batch -s ./ -d '$web' --account-name "$(STORAGE_ACCOUNT_NAME)" --overwrite --account-key "$(STORAGE_ACCOUNT_KEY)" Problem When running this command in the QA environment, I'm receiving the following error message: ERROR: <urllib3.connection.HTTPSConnection object at 0x7ff24b791100>: Failed to establish a new connection: [Errno -2] Name or service not known

Related command

az storage blob upload-batch -s ./ -d '$web' --account-name "$(STORAGE_ACCOUNT_NAME)" --overwrite --account-key "$(STORAGE_ACCOUNT_KEY)"

Errors

ERROR: <urllib3.connection.HTTPSConnection object at 0x7ff24b791100>: Failed to establish a new connection: [Errno -2] Name or service not known

Issue script & Debug output

ERROR: <urllib3.connection.HTTPSConnection object at 0x7ff24b791100>: Failed to establish a new connection: [Errno -2] Name or service not known

Expected behavior

It should upload the files to Azure storage account

Environment Summary

Task : Azure CLI Description : Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent. Version : 2.225.0 Author : Microsoft Corporation

Additional context

No response

yonzhan commented 10 months ago

Thank you for opening this issue, we will look into it.

azure-client-tools-bot-prd[bot] commented 10 months ago
Hi @anilsakr Find similar issue https://github.com/Azure/azure-cli/issues/21247.
Issue title az login: Failed to establish a new connection: [Errno -2] Name does not resolve
Create time 2022-02-10
Comment number 14

Possible solution: It seems that you are encountering a connectivity issue when running an Azure CLI command in your QA environment. The error message you received is: ERROR: <urllib3.connection.HTTPSConnection object at 0x7ff24b791100>: Failed to establish a new connection: [Errno -2] Name or service not known.

A similar issue was reported before, where the user encountered an error message: <urllib3.connection.HTTPSConnection object at 0x7f3ed60e6490>: Failed to establish a new connection: [Errno -2] Name does not resolve when trying to log in with Azure CLI inside of a container.

The solution provided in the previous issue was to test if the container can resolve login.microsoftonline.com by running the following commands:

apt-get update
apt install dnsutils
nslookup login.microsoftonline.com

You can try running these commands in your QA environment to see if the container can resolve the domain name. If the result is similar to the one provided in the previous issue, then the issue might be related to the DNS resolution in your environment.


Please confirm if this resolves your issue.

anilsakr commented 10 months ago

Also wanted to mention, Actually same pipeline code and network configs are working for Dev environment even am able to deploy using MS hosted agent but when I run in QA its throwing this error. As suggested tried nslookup login.microsoftonline.com in self hosted agent, its able to resolve, below is the out put,

Server:     10.60.12.8
Address:    10.60.12.8#53

Non-authoritative answer:
login.microsoftonline.com   canonical name = login.mso.msidentity.com.
login.mso.msidentity.com    canonical name = ak.privatelink.msidentity.com.
ak.privatelink.msidentity.com   canonical name = www.tm.ak.prd.aadg.trafficmanager.net.
Name:   www.tm.ak.prd.aadg.trafficmanager.net
Address: 20.190.190.129
Name:   www.tm.ak.prd.aadg.trafficmanager.net
Address: 20.190.190.130
Name:   www.tm.ak.prd.aadg.trafficmanager.net
Address: 20.190.190.131
Name:   www.tm.ak.prd.aadg.trafficmanager.net
Address: 20.190.190.132

Is there anything we need to check on Cloud-Init Configuration?

calvinhzy commented 10 months ago

What is the cli version by running az version? If it is indeed 2.225.0, please try to upgrade to the latest version by https://learn.microsoft.com/en-us/cli/azure/update-azure-cli

PeterThomasAwen commented 10 months ago

Just wanted to say I also get a similar error if the account name was incorrect, when using az storage file download-batch
I'd do an echo and check (STORAGE_ACCOUNT_NAME) is what you expect it to be.

Maybe a better error can be provided?

Running Az version 2.52.0

fabio-s-franco commented 6 months ago

Just wanted to say I also get a similar error if the account name was incorrect, when using az storage file download-batch I'd do an echo and check (STORAGE_ACCOUNT_NAME) is what you expect it to be.

Maybe a better error can be provided?

Running Az version 2.52.0

Agreed, I had a similar experience with the key vault, the message is not helpful to pinpoint the problem, in fact it will mislead towards unrelated issues.

sofia-valles commented 5 months ago

Is there any update on this issue? I'm also getting this error upon running az storage blob upload. I've already confirmed that I am referring to the correct storage account, permissions are in place and the resolving works.

calvinhzy commented 5 months ago

Hi @sofia-valles, can you help provide the detailed environment info? Are you also using a QA environment and what OS/terminal are you using? Wondering if any of the solutions in https://github.com/Azure/azure-cli/issues/21247 might be helpful.

r4hulp commented 4 months ago

Is there any update on this issue? I'm also getting this error upon running az storage blob upload. I've already confirmed that I am referring to the correct storage account, permissions are in place and the resolving works.

Did it work for you? This is failing in our case as well. We are trying to upload a blob via Azure DevOps Pipeline.

r4hulp commented 4 months ago

@calvinhzy -

In our case, it is one of the Azure DevOps agent (Linux - ubuntu-latest with version 3.234.0)

image

Starting: Upload key tab to repository
==============================================================================
Task         : Azure CLI
Description  : Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
Version      : 2.230.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
/usr/bin/az --version
azure-cli                         2.57.0

core                              2.57.0
telemetry                          1.1.0

Extensions:
azure-devops                      0.26.0

Dependencies:
msal                              1.26.0
azure-mgmt-resource             23.1.0b2
almmechanics commented 4 months ago

Likewise - i'm experiencing exactly the same from Azure DevOps using Azure CLI 2.57.0 on build agent ubuntu-latest on 3.234.0

Itsamirmasoud commented 1 month ago

Experiencing the same thing when trying to batch upload to an Azure Storage account. We have 4 env, works well on 3 and fails on 1 of them.

yusbel commented 1 month ago

I'm receiving the same error when listing secrets from Azure KeyVault or setting new secrets. I receive this error using the portal shell and using locally the az cli after sucessfull authentication.

az keyvault secret list --vault-name "keyvaultname" -o table <urllib3.connection.HTTPSConnection object at 0x7f2cad608d60>: Failed to establish a new connection: [Errno -2] Name or service not known

Any hint? Thank you

yusbel commented 1 month ago

I was able to connect without error after restarting the computer