'Can not login using az

When I try to login using az (az login), it's giving beloe error in ubuntu.. What is the possible solution for it??

Error:

Port '8400' is taken with error '[Errno 99] Cannot assign requested address'. Trying with the next one  
Port '8401' is taken with error '[Errno 99] Cannot assign requested address'. Trying with the next one
Port '8402' is taken with error '[Errno 99] Cannot assign requested address'. Trying with the next one
Port '8403' is taken with error '[Errno 99] Cannot assign requested address'. Trying with the next one
.
.
Port '8998' is taken with error '[Errno 99] Cannot assign requested address'. Trying with the next one
Port '8999' is taken with error '[Errno 99] Cannot assign requested address'. Trying with the next one
Error: can't reserve a port for authentication reply url
Login failed


Solution 1:[1]

Check you /etc/hosts file if you are on linux. Add entry as , 127.0.0.1 localhost

and retry. It should resolve the issue.

Solution 2:[2]

I doubt this is still relevant after two years, but since I encountered a similar issue and ran into this post, I think it's worth noting the solution I found.

What worked for me was using:

az login --use-device-code

As Microsoft recommends here- https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli#sign-in-interactively

It doesn't use localhost / ports at all, and you can complete the process from whatever computer you want, or if login fails... So it may be relevant for you.

@Nancy Xiong referred you to a solution relying on this extra parameter in the comments, so credits to @nancy-xiong as well ?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ravi Mandli
Solution 2 Reckless Engineer