Skip to content

Commit 421aefd

Browse files
committed
do call to authorization api
given it requires 2FA, the generate token call is going to fail but thats going to send 2FA code properly
1 parent 12996c5 commit 421aefd

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

doctr/local.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ def GitHub_login(*, username=None, password=None, OTP=None, headers=None):
128128
if r.status_code == 401:
129129
two_factor = r.headers.get('X-GitHub-OTP')
130130
if two_factor:
131+
auth_header = base64.urlsafe_b64encode(bytes(username + ':' + password, 'utf8')).decode()
132+
login_kwargs = {'auth': None, 'headers': {'Authorization': 'Basic {}'.format(auth_header)}}
133+
try:
134+
generate_GitHub_token(**login_kwargs)
135+
except requests.exceptions.HTTPError:
136+
pass
131137
print("A two-factor authentication code is required:", two_factor.split(';')[1].strip())
132138
OTP = input("Authentication code: ")
133139
return GitHub_login(username=username, password=password, OTP=OTP, headers=headers)

0 commit comments

Comments
 (0)