Using Two-factor Authentication with github3.py
GitHub recently added support for Two-factor Authentication togithub.comand shortly thereafter added support for it onapi.github.com. In version0.8, github3.py also added support for it and you can use it right now.
To use Two-factor Authentication, you must define your own function that willreturn your one time authentication code. You then provide that function whenlogging in with github3.py.
For example:
importgithub3defmy_two_factor_function():# The user could accidentally press Enter before being ready,# let's protect them from doing that.returninput('Enter 2FA code: ').strip()ormy_two_factor_function()g=github3.login('sigmavirus24','my_password',two_factor_callback=my_two_factor_function)
Then each time the API tells github3.py it requires a Two-factor Authenticationcode, github3.py will callmy_two_factor_function which prompt you for it.