+ 1

Logging in to Telegram using Telethon

Hi, I am trying to access my telegram account through Python using telethon. However, my code runs and does nothing happens, only 2 documents (called .session) get created on my desktop. Whenever I run the code again while these 2 documents are on my desktop, I get an error: OperationalError: database is locked. However, if I delete these documents, then my code runs, but again nothing happens. I seem to understand how the library works, but it literally has almost no explanation about how to log in to my account before starting to use all of the methods they have in the library. Here is the code I am running (on Anaconda Spyder): api_id = ******** api_hash = "*********************************" phone = "************" #obviously I have the correct values instead of the * signs client = TelegramClient('some_name', api_id, api_hash) client.connect() if not client.is_user_authorized(): client.send_code_request(phone) client.sign_in(phone, input("Verification code: ")) me = client.get_me() print(me) Thanks for any help, I seem to be very stuck here.

8th Oct 2021, 3:43 AM
Sergey
1 Antwort
0
Try with api_id = ******** api_hash = "*********************************" client = TelegramClient('some_name', api_id, api_hash) async def start(): me = await client.get_me() print(me) if __name__=="__main__": client.start() client.loop.run_until_complete(start()) client.loop.run_forever(); Telethon is async lib then when client.start() is called it prompt the phone number and send code request, when your Enter the code it execute start(), that execute the code The last time that your execute again it don't prompt the number
15th Oct 2021, 5:41 PM
Nyashi