Fix start not asking for password if needed

This commit is contained in:
Lonami Exo 2018-02-18 12:17:02 +01:00
parent 33fd6895d3
commit 1179c9e21b

View File

@ -1,3 +1,4 @@
import getpass
import hashlib import hashlib
import io import io
import itertools import itertools
@ -216,8 +217,8 @@ class TelegramClient(TelegramBareClient):
def start(self, def start(self,
phone=lambda: input('Please enter your phone: '), phone=lambda: input('Please enter your phone: '),
password=None, bot_token=None, password=lambda: getpass.getpass('Please enter your password: '),
force_sms=False, code_callback=None, bot_token=None, force_sms=False, code_callback=None,
first_name='New User', last_name=''): first_name='New User', last_name=''):
""" """
Convenience method to interactively connect and sign in if required, Convenience method to interactively connect and sign in if required,
@ -331,6 +332,9 @@ class TelegramClient(TelegramBareClient):
"Two-step verification is enabled for this account. " "Two-step verification is enabled for this account. "
"Please provide the 'password' argument to 'start()'." "Please provide the 'password' argument to 'start()'."
) )
# TODO If callable given make it retry on invalid
if callable(password):
password = password()
me = self.sign_in(phone=phone, password=password) me = self.sign_in(phone=phone, password=password)
# We won't reach here if any step failed (exit by exception) # We won't reach here if any step failed (exit by exception)