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

Capitalization of the 2FA OTP request header #275

Merged
merged 1 commit into from
Sep 28, 2014

Conversation

tradej
Copy link
Contributor

@tradej tradej commented Sep 24, 2014

Running

from github import Github
user = Github(login_or_token='username', password='password').get_user()
try:                                                                               
    auth = user.create_authorization(scopes=['repo'], note='test')
except GithubException:                                                         
    password = input()                                                             
    auth = user.create_authorization(scopes=['repo'], note='test', onetime_password=password)

yields a TwoFactorException with the following traceback:

Traceback (most recent call last):
  File "./mygithub.py", line 9, in <module>
    auth = user.create_authorization(scopes=['repo'], note='test')
  File "/home/tradej/.local/lib/python3.3/site-packages/github/AuthenticatedUser.py", line 436, in create_authorization
    headers=request_header,
  File "/home/tradej/.local/lib/python3.3/site-packages/github/Requester.py", line 169, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
  File "/home/tradej/.local/lib/python3.3/site-packages/github/Requester.py", line 177, in __check
    raise self.__createException(status, responseHeaders, output)
github.GithubException.TwoFactorException: 401 {'documentation_url': 'https://developer.github.com/v3/auth#working-with-two-factor-authentication', 'message': 'Must specify two-factor authentication OTP code.'}

This is caused by the OTP header string being all lowercase. If it is properly uppercased as in this pull request, the authentication process finishes correctly.

@jacquev6
Copy link
Member

Thanks!

This is consistent with what I've just done in PyGithub v2 so I'll merge it soon and publish a new version of PyGithub v1.

Side note: HTTP headers are supposed to be case-insensitive.

@jacquev6 jacquev6 self-assigned this Sep 24, 2014
@tradej
Copy link
Contributor Author

tradej commented Sep 25, 2014

Thank you too. I know that they should be case insensitive, but honestly, I think GitHub's API is a kind of a mess, and this behaviour does not exactly surprise me. I'll file a bug for it.

@jacquev6 jacquev6 merged commit cff1a42 into PyGithub:develop Sep 28, 2014
@jacquev6
Copy link
Member

Merged and published in https://pypi.python.org/pypi/PyGithub/1.25.1

Thanks!

@tradej
Copy link
Contributor Author

tradej commented Sep 29, 2014

Thank you for merging. I sent a support ticket to GitHub concerning this behaviour and they acknowledged it.

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

Successfully merging this pull request may close these issues.

2 participants