`az login` fails with "Failed to establish a new connection: [Errno -2] Name or service not known'"

Kashif Ilyas 0 Reputation points
2023-01-23T10:28:45.4966667+00:00

I continously get this error when I try to login using az login from my Ubunut 20.04 VM. There are no internet issues and all microsoft services are apparently accessible from the machine. After 7-10 retires, it finally succeeds. This is very annoying. Can someone help?

Here is the backtrace:

A web browser has been opened at https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
The command failed with an unexpected error. Here is the traceback:
HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /organizations/oauth2/v2.0/token (Caused by NewConnectionError('
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,068 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ovidiu Borlean 1 Reputation point Microsoft Employee
    2023-01-23T19:35:21.94+00:00

    Hello Kashif**,**

    Thank you for reaching out to Microsoft Q&A!

    From the provided output it seems to be related to a name resolution issue. If you are not running behind a proxy server that could interfere with the traffic between your host and login.microsoft.com. You can try add a public DNS server (8.8.8.8) in your /etc/resolv.conf and check if the problem persist.

    If the reply was helpful, please don’t forget to upvote or accept as answer,

    Thank you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.