Cannot login from mac M1
Hi, it seems that I cannot login from a notebook in mac M1. In this version I'm using Python 3.9.12. I have tried both using a token and without it.
This is the code that I'm using, I have tried this same code in a kaggle notebook (python 3.7.12) and it works fine.
dagshub_token = os.getenv("DAGSHUB_TOKEN")
dagshub.auth.add_app_token(token=dagshub_token)
dagshub.init(kaggle_competition, dagshub_username, mlflow=True)
and here's the traceback:
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
Cell In[13], line 3
1 dagshub_token = os.getenv("DAGSHUB_TOKEN")
2 dagshub.auth.add_app_token(token="mysupersecrettoken")
----> 3 dagshub.init(kaggle_competition, dagshub_username, mlflow=True)
File ~/.conda/envs/machine-learning/lib/python3.10/site-packages/dagshub/common/init.py:57, in init(repo_name, repo_owner, url, root, host, mlflow, dvc)
53 res = http_request("GET", urllib.parse.urljoin(host, config.REPO_INFO_URL.format(
54 owner=repo_owner,
55 reponame=repo_name)), auth=bearer)
56 if res.status_code == 404:
---> 57 create_repo(repo_name)
59 # Configure MLFlow
60 if mlflow:
File ~/.conda/envs/machine-learning/lib/python3.10/site-packages/dagshub/upload/wrapper.py:108, in create_repo(repo_name, org_name, description, private, auto_init, gitignores, license, readme, template, host)
105 if token is not None:
106 auth = HTTPBearerAuth(token)
--> 108 if auth is None:
109 raise RuntimeError("You can't create a repository without being authenticated.")
111 if (license != "" or readme != "" or gitignores != "") and template == "none":
UnboundLocalError: local variable 'auth' referenced before assignment
Any ideas?
Hi there!
Can you try adding the token via the CLI? It will be cached for later use so you won't have to login again
dagshub login --token "<token>"
This should call the same function you're calling from your python code, but maybe there's something missing.
Let me know how it goes
Hi kbolashev, thanks for you quick reply!
It seems that the token is added without issues, but unfortunately, it's giving me the same error.
This is my CLI
(machine-learning) isaacgonzalez@MacBook-Pro-2 myproject % dagshub login --token mytoken
✅ Token added successfully
(machine-learning) isaacgonzalez@MacBook-Pro-2 myproject % cd ~/Documents
(machine-learning) isaacgonzalez@MacBook-Pro-2 Documents % jupyter notebook
I found the problem! :D
It seems that every time that I run this line dagshub.auth.add_app_token(token=dagshub_token), it adds a new set of lines to the tokens file (in /Users/myuser/Library/Caches/dagshub/tokens).
And because the first time I added the token I missed to correctly read my env variable, the first lines of this file was:
https://dagshub.com:
- access_token: null
expiry: never
token_type: app-token
So that's why get_token was always returning None.
BTW, every time I call dagshub.auth.add_app_token(token=dagshub_token) it's adding a new chunk of lines to the tokens file, even though my token is already present in the token file.
Maybe it should check if the token already exists before adding it?
Glad you got it figured out! We need to add a clean-up feature to the cache that checks if the tokens are valid or not, or at the very least cache clean up. 😄 Right now we just check the expiry date, but if you manage to add an invalid token it just stays there.
And yea, we're not checking if the token exists or not. In general just adding a token once should be fine and you can get rid of the add_app_token call now.
Another thing for us to fix