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

Quickstart does not function #1092

Open
xiongchiamiov opened this issue Jun 8, 2022 · 1 comment
Open

Quickstart does not function #1092

xiongchiamiov opened this issue Jun 8, 2022 · 1 comment

Comments

@xiongchiamiov
Copy link
Contributor

I'm trying to update a very old project of mine that uses github3.py. I've been having difficulties getting even just the authorization to work, and it appears that the basic examples at the start of the documentation don't work. People appear to be using this successfully! so I'm not sure what's going on here. Here's a complete reproduction starting from an empty directory:

┌─[jamesph@Jamess-MBP] - [~/temp/github] - [Wed Jun 08, 02:44]
└─[$]> ls -A
┌─[jamesph@Jamess-MBP] - [~/temp/github] - [Wed Jun 08, 02:44]
└─[$]> python3 -m venv env
┌─[jamesph@Jamess-MBP] - [~/temp/github] - [Wed Jun 08, 02:45]
└─[$]> source env/bin/activate
(env) ┌─[jamesph@Jamess-MBP] - [~/temp/github] - [Wed Jun 08, 02:45]
└─[$]> pip install github3.py==3.2.0
Collecting github3.py==3.2.0
  Using cached github3.py-3.2.0-py2.py3-none-any.whl (152 kB)
Collecting python-dateutil>=2.6.0
  Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting requests>=2.18
  Using cached requests-2.27.1-py2.py3-none-any.whl (63 kB)
Collecting uritemplate>=3.0.0
  Using cached uritemplate-4.1.1-py2.py3-none-any.whl (10 kB)
Collecting PyJWT[crypto]>=2.3.0
  Using cached PyJWT-2.4.0-py3-none-any.whl (18 kB)
Collecting cryptography>=3.3.1
  Using cached cryptography-37.0.2-cp36-abi3-macosx_10_10_universal2.whl (5.3 MB)
Collecting six>=1.5
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.3-py3-none-any.whl (61 kB)
Collecting urllib3<1.27,>=1.21.1
  Using cached urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2022.5.18.1-py3-none-any.whl (155 kB)
Collecting charset-normalizer~=2.0.0
  Using cached charset_normalizer-2.0.12-py3-none-any.whl (39 kB)
Collecting cffi>=1.12
  Using cached cffi-1.15.0-cp39-cp39-macosx_11_0_arm64.whl (173 kB)
Collecting pycparser
  Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Installing collected packages: urllib3, uritemplate, six, PyJWT, pycparser, idna, charset-normalizer, certifi, requests, python-dateutil, cffi, cryptography, github3.py
Successfully installed PyJWT-2.4.0 certifi-2022.5.18.1 cffi-1.15.0 charset-normalizer-2.0.12 cryptography-37.0.2 github3.py-3.2.0 idna-3.3 pycparser-2.21 python-dateutil-2.8.2 requests-2.27.1 six-1.16.0 uritemplate-4.1.1 urllib3-1.26.9
WARNING: There was an error checking the latest version of pip.
(env) ┌─[jamesph@Jamess-MBP] - [~/temp/github] - [Wed Jun 08, 02:45]
└─[$]> pip freeze
certifi==2022.5.18.1
cffi==1.15.0
charset-normalizer==2.0.12
cryptography==37.0.2
github3.py==3.2.0
idna==3.3
pycparser==2.21
PyJWT==2.4.0
python-dateutil==2.8.2
requests==2.27.1
six==1.16.0
uritemplate==4.1.1
urllib3==1.26.9
(env) ┌─[jamesph@Jamess-MBP] - [~/temp/github] - [Wed Jun 08, 02:45]
└─[$]> python
Python 3.9.13 (main, May 24 2022, 21:13:51)
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from github3 import login
>>> gh = login('xiongchiamiov', password='<redacted>')
>>> gh.me()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jamesph/temp/github/env/lib/python3.9/site-packages/github3/decorators.py", line 24, in auth_wrapper
    return func(self, *args, **kwargs)
  File "/Users/jamesph/temp/github/env/lib/python3.9/site-packages/github3/github.py", line 1549, in me
    json = self._json(self._get(url), 200)
  File "/Users/jamesph/temp/github/env/lib/python3.9/site-packages/github3/models.py", line 161, in _json
    raise exceptions.error_for(response)
github3.exceptions.AuthenticationFailed: 401 Requires authentication

I thought maybe it had something to do with having 2fa enabled on my account, so I tried that:

>>> def f():
...   return input('2fa: ').strip()
...
>>> gh = login('xiongchiamiov', password='<redacted>', two_factor_callback=f)
>>> gh.me()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jamesph/temp/github/env/lib/python3.9/site-packages/github3/decorators.py", line 24, in auth_wrapper
    return func(self, *args, **kwargs)
  File "/Users/jamesph/temp/github/env/lib/python3.9/site-packages/github3/github.py", line 1549, in me
    json = self._json(self._get(url), 200)
  File "/Users/jamesph/temp/github/env/lib/python3.9/site-packages/github3/models.py", line 161, in _json
    raise exceptions.error_for(response)
github3.exceptions.AuthenticationFailed: 401 Requires authentication

And then even tried explicitly authorizing the object (which is weird because I'm having to pass the username and password again into an object that already has them), which gives a new error but still not any success:

>>> gh
<GitHub [basic xiongchiamiov]>
>>> gh.authorize('xiongchiamiov', '<redacted>')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jamesph/temp/github/env/lib/python3.9/site-packages/github3/github.py", line 499, in authorize
    json = self._json(self._post(url, data=data), 201)
  File "/Users/jamesph/temp/github/env/lib/python3.9/site-packages/github3/models.py", line 161, in _json
    raise exceptions.error_for(response)
github3.exceptions.NotFoundError: 404 Not Found
>>>

(Inspecting into that, btw, gives the url as https://api.github.com/authorizations. That endpoint appears to have been removed in 2020, which I guess is what #986 is about.)

@meator
Copy link

meator commented Dec 18, 2022

I am facing the same issue You are describing. I think it is because of this: https://docs.github.com/en/rest/overview/other-authentication-methods#basic-authentication

It says that using usernames and passwords for auth is discontinued. Personal access tokens (and other methods described in the link) should work.

If this is true than it should certainly be documented in github3.py documentation. I found the GitHub page by accident.

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

No branches or pull requests

2 participants