Skip to content

Capitalization of the 2FA OTP request header#275

Merged
jacquev6 merged 1 commit into
PyGithub:developfrom
tradej:develop
Sep 28, 2014
Merged

Capitalization of the 2FA OTP request header#275
jacquev6 merged 1 commit into
PyGithub:developfrom
tradej:develop

Conversation

@tradej

@tradej tradej commented Sep 24, 2014

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

tradej commented Sep 25, 2014

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Member

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

Thanks!

@tradej

tradej commented Sep 29, 2014

Copy link
Copy Markdown
Contributor Author

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