Repository: wandb/wandb

Issue:
[CLI]: 401 Unauthorized error
### Describe the bug

<!--- Description of the issue below  -->

I have set up a GCP VM instance and the wandb login seems fine (the key appears in the `~/.netrc/, etc.).
```
❯ wandb login
wandb: W&B API key is configured. Use `wandb login --relogin` to force relogin
```
I've also used this setup in other GCP projects with no issues. However on this particular instance, I'm getting errors when I try to call `wandb.init`:

```
>>> wandb.__version__
'0.14.2'
>>> wandb.init(project="hippo")
wandb: W&B API key is configured. Use `wandb login --relogin` to force relogin
wandb: ERROR Error while calling W&B API: user is not logged in (<Response [401]>)
Problem at: <stdin> 1 <module>
wandb: ERROR The API key is either invalid or missing, or the host is incorrect. To resolve this issue, you may try running the 'wandb login --host [hostname]' command. The host defaults to 'https://api.wandb.ai' if not specified. (Error 401: Unauthorized)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/envs/s4/lib/python3.10/site-packages/wandb/sdk/wandb_init.py", line 1164, in init
    raise e
  File "/opt/conda/envs/s4/lib/python3.10/site-packages/wandb/sdk/wandb_init.py", line 1145, in init
    run = wi.init()
  File "/opt/conda/envs/s4/lib/python3.10/site-packages/wandb/sdk/wandb_init.py", line 764, in init
    raise error
wandb.errors.AuthenticationError: The API key is either invalid or missing, or the host is incorrect. To resolve this issue, you may try running the 'wandb login --host [hostname]' command. The host defaults to 'https://api.wandb.ai' if not specified. (Error 401: Unauthorized)
```

I did some searching around on the internet and in the wandb issues/discussions and can't see any information about this.

### Additional Files

_No response_

### Environment

WandB version: 0.14.2

OS: Debian GNU/Linux 10 (buster)

Python version: 3.10.10

Versions of relevant libraries:


### Additional Context

_No response_


Discussion:
Hi @albertfgu thanks for reporting this issue. Do you have any `WANDB_` environment variables exported in this VM instance? Are you also logging results to the public cloud `wandb.ai`, or to a local W&B instance? 
You're right, turns out I had a `WANDB_API_KEY` set to a different key, and deleting it fixes the problem. I remember I used to use that workflow; has `WANDB_API_KEY` been deprecated and subsumed by the `wandb login` workflow? Perhaps it could be useful to generate a more informative error message in a case such as mine?

Thanks for the help!

Resolving patch:
diff --git a/wandb/util.py b/wandb/util.py
--- a/wandb/util.py
+++ b/wandb/util.py
@@ -50,7 +50,7 @@
 import yaml
 
 import wandb
-from wandb.env import get_app_url
+import wandb.env
 from wandb.errors import AuthenticationError, CommError, UsageError, term
 from wandb.sdk.lib import filesystem, runid
 
@@ -256,7 +256,7 @@ def get_optional_module(name) -> Optional["importlib.ModuleInterface"]:  # type:
 def app_url(api_url: str) -> str:
     """Return the frontend app url without a trailing slash."""
     # TODO: move me to settings
-    app_url = get_app_url()
+    app_url = wandb.env.get_app_url()
     if app_url is not None:
         return str(app_url.strip("/"))
     if "://api.wandb.test" in api_url:
@@ -881,9 +881,11 @@ def no_retry_auth(e: Any) -> bool:
     # Crash w/message on forbidden/unauthorized errors.
     if e.response.status_code == 401:
         raise AuthenticationError(
-            "The API key is either invalid or missing, or the host is incorrect. "
-            "To resolve this issue, you may try running the 'wandb login --host [hostname]' command. "
-            "The host defaults to 'https://api.wandb.ai' if not specified. "
+            "The API key you provided is either invalid or missing.  "
+            f"If the `{wandb.env.API_KEY}` environment variable is set, make sure it is correct. "
+            "Otherwise, to resolve this issue, you may try running the 'wandb login --relogin' command. "
+            "If you are using a local server, make sure that you're using the correct hostname. "
+            "If you're not sure, you can try logging in again using the 'wandb login --relogin --host [hostname]' command."
             f"(Error {e.response.status_code}: {e.response.reason})"
         )
     elif wandb.run:


Test patch: