Switch to SessionPasswordNeededError

This commit is contained in:
Tanuj 2017-09-18 18:44:16 +01:00
parent 619c35986b
commit df31a03788

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# disclaimer: you should not actually use this. it can be quite spammy. # disclaimer: you should not actually use this. it can be quite spammy.
from time import sleep
from telethon import TelegramClient from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
from getpass import getpass from getpass import getpass
from telethon.tl.types import InputPeerUser,InputPeerChannel from telethon.tl.types import InputPeerUser,InputPeerChannel
from telethon.tl.types import Updates from telethon.tl.types import Updates
@ -10,6 +10,7 @@ from telethon.tl.functions.messages import SendMessageRequest,EditMessageRequest
from telethon.tl.types import MessageService from telethon.tl.types import MessageService
from nltk.tokenize import word_tokenize from nltk.tokenize import word_tokenize
from os import environ from os import environ
from time import sleep
CHANNELS = {} CHANNELS = {}
CHANNELNAMES = {} CHANNELNAMES = {}
@ -47,12 +48,10 @@ class NeedsMore(TelegramClient):
code = input('Enter the auth code: ') code = input('Enter the auth code: ')
try: try:
code_ok = self.sign_in(user_phone, code) code_ok = self.sign_in(user_phone, code)
except RPCError as e: except SessionPasswordNeededError:
if e.password_required: if e.password_required:
pw = getpass('Two step verification enabled. Please enter your password: ') pw = getpass('Two step verification enabled. Please enter your password: ')
self.sign_in(password=pw) self.sign_in(password=pw)
else:
raise e
print('INFO: Client initialized succesfully!') print('INFO: Client initialized succesfully!')
def run(self): def run(self):