Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate nbdev-template github API call #940

Closed
eaubin opened this issue Aug 26, 2022 · 4 comments
Closed

Authenticate nbdev-template github API call #940

eaubin opened this issue Aug 26, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@eaubin
Copy link

eaubin commented Aug 26, 2022

nbdev_new fails for me getting the latest release tag using the github API. Someone at my organization keeps exceeding the rate limit, so github is in the right here. The particular failure is

Traceback (most recent call last):
  File "/opt/anaconda3/envs/proj/bin/nbdev_new", line 8, in <module>
    sys.exit(nbdev_new())
  File "/opt/anaconda3/envs/proj/lib/python3.9/site-packages/fastcore/script.py", line 117, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/opt/anaconda3/envs/proj/lib/python3.9/site-packages/nbdev/cli.py", line 103, in nbdev_new
    tag = urljson('https://api.github.com/repos/fastai/nbdev-template/releases/latest')['tag_name']
  File "/opt/anaconda3/envs/proj/lib/python3.9/site-packages/fastcore/net.py", line 125, in urljson
    res = urlread(url, data=data, timeout=timeout)
  File "/opt/anaconda3/envs/proj/lib/python3.9/site-packages/fastcore/net.py", line 115, in urlread
    if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None
fastcore.basics.HTTP403ForbiddenError: HTTP Error 403: Forbidden

I think I can get around this by modifying the editing the file, but in a perfect world I'd be able to run the command offline, without any internet access at all. Could the templates be installed for offline use? If not, could the API call be authenticated?

@jph00 jph00 changed the title nbdev_new run time dependency on github Authenticate nbdev-template github API call Aug 26, 2022
@jph00 jph00 added the enhancement New feature or request label Aug 26, 2022
@jph00 jph00 closed this as completed in c09b077 Aug 26, 2022
@jph00
Copy link
Contributor

jph00 commented Aug 26, 2022

I've switched it over to using ghapi, so if you set GITHUB_TOKEN env var then it should work now.

Please reopen this if it turns out there's still an issue.

@lgonzalezsa
Copy link

lgonzalezsa commented Sep 2, 2022

I don't know if its related but trying with my existing repos to do nbdev_new and fails with AttributeError: topics
If I unset GITHUB_TOKEN then am able to reach the prompt to put description but then warning me that I dont have the token set and fail with raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None (see second traceback).
By the way, am behind GitHub Enterprise not github.com

nbdev_new
Traceback (most recent call last):
  File "/home/gonluisr/miniconda3/envs/conda_dev/bin/nbdev_new", line 8, in <module>
    sys.exit(nbdev_new())
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/fastcore/script.py", line 119, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/nbdev/cli.py", line 101, in nbdev_new
    nbdev_create_config.__wrapped__(**kwargs)
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/nbdev/config.py", line 168, in nbdev_create_config
    inf = _fetch_from_git()
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/nbdev/config.py", line 103, in _fetch_from_git
    res['branch'],res['keywords'],desc = _get_info(owner=res['user'], repo=res['repo'])
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/nbdev/config.py", line 94, in _get_info
    return r.default_branch, default_kw if not r.topics else ' '.join(r.topics), r.description
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/fastcore/basics.py", line 247, in __getattr__
    def __getattr__(self,k): return self[k] if k in self else stop(AttributeError(k))
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/fastcore/basics.py", line 216, in stop
    raise e
AttributeError: topics
nbdev_new
/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/ghapi/core.py:99: UserWarning: Neither GITHUB_TOKEN nor GITHUB_JWT_TOKEN found: running as unauthenticated
  else: warn('Neither GITHUB_TOKEN nor GITHUB_JWT_TOKEN found: running as unauthenticated')
Could not access repo: enterprise/the_repo to find your default branch - `main` assumed.
Edit `settings.ini` if this is incorrect.
In the future, you can allow nbdev to see private repos by setting the environment variable GITHUB_TOKEN as described here:
https://nbdev.fast.ai/cli.html#Using-nbdev_new-with-private-repos
repo = the_repo # Automatically inferred from git
user = enterprise # Automatically inferred from git
author = Luis Rolando Gonzalez # Automatically inferred from git
author_email = luis.gs@enterprise.com # Automatically inferred from git
# Please enter a value for description
description = Dask get_file demo
settings.ini created.
/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/ghapi/core.py:99: UserWarning: Neither GITHUB_TOKEN nor GITHUB_JWT_TOKEN found: running as unauthenticated
  else: warn('Neither GITHUB_TOKEN nor GITHUB_JWT_TOKEN found: running as unauthenticated')
Traceback (most recent call last):
  File "/home/gonluisr/miniconda3/envs/conda_dev/bin/nbdev_new", line 8, in <module>
    sys.exit(nbdev_new())
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/fastcore/script.py", line 119, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/nbdev/cli.py", line 106, in nbdev_new
    tag = GhApi().repos.get_latest_release('fastai', 'nbdev-template').tag_name
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/ghapi/core.py", line 61, in __call__
    return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/ghapi/core.py", line 118, in __call__
    res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=debug, return_headers=True,
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/fastcore/net.py", line 214, in urlsend
    return urlread(req, return_json=return_json, return_headers=return_headers)
  File "/home/gonluisr/miniconda3/envs/conda_dev/lib/python3.10/site-packages/fastcore/net.py", line 115, in urlread
    if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None

I am using:

conda list | grep "fastai"
execnb                    0.1.2                      py_0    fastai
fastcore                  1.5.24                     py_0    fastai
ghapi                     1.0.2                      py_0    fastai
nbdev                     2.2.10                     py_0    fastai

PS: Seems https://nbdev.fast.ai/cli.html#Using-nbdev_new-with-private-repos is broken link returned in the latest traceback

@jph00
Copy link
Contributor

jph00 commented Sep 2, 2022

@lgonzalezsa can you please create a new issue?

@lgonzalezsa
Copy link

Done.
#977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants