github3.py icon indicating copy to clipboard operation
github3.py copied to clipboard

Token example does not work

Open haizaar opened this issue 9 years ago • 8 comments

I'm trying to use token example from the documentation.

I've put the first snippet into fetch-creds.py and the second one to use-creds.py. Fetching went OK, and I indeed saw a personal token on my GitHub profile, however the second snippet fails with:

Traceback (most recent call last):
  File "use-creds.py", line 9, in <module>
    auth = gh.authorization(id)
  File "/home/haizaar/.../lib/python3.4/site-packages/github3/decorators.py", line 66, in auth_wrapper
    raise GitHubError(r)
github3.models.GitHubError: 401 Requires username/password authentication

I've verified that credentials are correct by using basic auth through github3.login. Here is the snippet code exactly as I run it:

from github3 import login

token = id = ''
with open("/tmp/creds", 'r') as fd:
    token = fd.readline().strip()  # Can't hurt to be paranoid
    id = fd.readline().strip()

gh = login(token=token)
auth = gh.authorization(id)
auth.update(add_scopes=['repo:status', 'gist'], rm_scopes=['user'])

# if you want to be really paranoid, you can then test:
# token == auth.token
# in case the update changes the token

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/33363501-token-example-does-not-work?utm_campaign=plugin&utm_content=tracker%2F183477&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F183477&utm_medium=issues&utm_source=github).

haizaar avatar Apr 26 '16 21:04 haizaar

Hey @haizaar , what version are you running? I'm going to try and reproduce.

itsmemattchung avatar Apr 27 '16 03:04 itsmemattchung

Thanks @haizaar for reporting this. I'm able to reproduce the issue:

  File "/Users/mattchung/Development/github3.py/github3/decorators.py", line 61, in auth_wrapper
    raise error_for(r)
github3.exceptions.AuthenticationFailed: 401 Requires username/password authentication

It is possible, in the past, that this example worked, since GitHub might've changed their API. If I use the basic authentication, instead of token, I do not get an exception:

gh = login(username='itsmemattchung', password='xxxxxx')

Looks like we'll need the documentation to get updated in order to reflect these changes.

itsmemattchung avatar Apr 27 '16 04:04 itsmemattchung

I'm running the latest version from PyPi. Basic auth works indeed (I supply the obtained ID as username and the token as password).

So do you know that's changed on GitHub side and how to use it now? On 27 Apr 2016 07:47, "Matt Chung" [email protected] wrote:

Thanks @haizaar https://github.com/haizaar for reporting this. I'm able to reproduce the issue:

File "/Users/mattchung/Development/github3.py/github3/decorators.py", line 61, in auth_wrapper raise error_for(r) github3.exceptions.AuthenticationFailed: 401 Requires username/password authentication

It is possible, in the past, that this example worked, since GitHub might've changed their API. If I use the basic authentication, instead of token, I do not get an exception:

gh = login(username='itsmemattchung', password='xxxxxx')

Looks like we'll need the documentation to get updated in order to reflect these changes.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/sigmavirus24/github3.py/issues/602#issuecomment-214968924

haizaar avatar Apr 27 '16 06:04 haizaar

I'm running the latest version from PyPi.

Please give us a version number or how you installed the package. There are actually two "latest" versions on PyPI.

sigmavirus24 avatar Apr 27 '16 14:04 sigmavirus24

Looks like we'll need the documentation to get updated in order to reflect these changes.

@itsmemattchung correct, I think this is a documentation problem stemming from GitHub changing their stable API in a backwards incompatible way.

sigmavirus24 avatar Apr 27 '16 14:04 sigmavirus24

Please give us a version number or how you installed the package. There are actually two "latest" versions on PyPI.

$ pip freeze                                                                                                                                                                                         
github3.py==0.9.5                                                                                                                                                                                                                            
requests==2.9.1                                                                                                                                                                                                                              
uritemplate.py==0.3.0

haizaar avatar Apr 27 '16 14:04 haizaar

there... https://developer.github.com/v3/oauth_authorizations/#deprecation-notice :-(

zeph avatar Oct 12 '16 08:10 zeph

It looks like this error message isn't actually from GitHub but is faked to make it more clear what's going on ( e3e6c3864baf6b720b0db5c2c8ddcc1eb9714c0a ). I see mention from @sigmavirus24 and @itsmemattchung of the fix here being documentation changes regarding the use of tokens.

What would (in rough terms) that documentation change be? Or another way to put it, what should I do to work around the 401 Requires username/password authentication error when trying to setup authorization with a token?

gene1wood avatar Jun 06 '17 22:06 gene1wood