LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
9.96k stars 1.4k forks source link

stuck while start() #4406

Open xlccccc opened 4 months ago

xlccccc commented 4 months ago

Code that causes the issue

import asyncio
from telethon import TelegramClient, errors
import logging
logging.basicConfig(level=logging.DEBUG)
api_id = ''
api_hash = ''
phone_number = ''

client = TelegramClient('session_name', api_id, api_hash)

async def main():
    await client.start(phone=phone_number)
    await client.disconnect()

if __name__ == '__main__':
    asyncio.run(main())

Expected behavior

Telegram received the verification code and successfully logged in after entering it

Actual behavior

Stuck when logging in

Traceback

No response

Telethon version

1.36

Python version

3.9.13

Operating system (including distribution name and version)

Windows 10

Other details

DEBUG:asyncio:Using proactor: IocpProactor
DEBUG:asyncio:Using proactor: IocpProactor
INFO:telethon.network.mtprotosender:Connecting to 149.154.175.57:443/TcpFull...
DEBUG:telethon.network.mtprotosender:Connection attempt 1...
DEBUG:telethon.network.mtprotosender:Connection success!
DEBUG:telethon.network.mtprotosender:Starting send loop
DEBUG:telethon.network.mtprotosender:Starting receive loop
INFO:telethon.network.mtprotosender:Connection to 149.154.175.57:443/TcpFull complete!
DEBUG:telethon.network.mtprotosender:Waiting for messages to send...
DEBUG:telethon.extensions.messagepacker:Assigned msg_id = 7389165337218010064 to InvokeWithLayerRequest (20a66ad8f10)
DEBUG:telethon.network.mtprotosender:Encrypting 1 message(s) in 76 bytes for sending
DEBUG:telethon.network.mtprotosender:Encrypted messages put in a queue to be sent
DEBUG:telethon.network.mtprotosender:Waiting for messages to send...
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
DEBUG:telethon.network.mtprotosender:Handling bad salt for message 7389165337218010064
DEBUG:telethon.network.mtprotosender:1 message(s) will be resent
DEBUG:telethon.network.mtprotosender:Receiving items from the network...

The log is stuck here all the time and no error is reported

Checklist

gensx-x1 commented 3 months ago

i'm currently having same issue, except im trying to run code on google cloud vm. it works perfectly on my machine, its stuck i same place as yours on vm.

mortalis13 commented 2 months ago

Something going on with the Telegram APIs maybe... Was receiving the unhelpful Server sent a very new message with ID 7410434973273745413, ignoring (see FAQ for details).

Thanks for the logging hint, getting similar debug logs but a bit more lines...

DEBUG:asyncio:Using proactor: IocpProactor
INFO:telethon.network.mtprotosender:Connecting to 149.154.167.91:443/TcpFull...
DEBUG:telethon.network.mtprotosender:Connection attempt 1...
DEBUG:telethon.network.mtprotosender:Connection success!
DEBUG:telethon.network.mtprotosender:Starting send loop
DEBUG:telethon.network.mtprotosender:Starting receive loop
INFO:telethon.network.mtprotosender:Connection to 149.154.167.91:443/TcpFull complete!
DEBUG:telethon.network.mtprotosender:Waiting for messages to send...
DEBUG:telethon.extensions.messagepacker:Assigned msg_id = 7410435962950057644 to InvokeWithLayerRequest (175b3260810)
DEBUG:telethon.network.mtprotosender:Encrypting 1 message(s) in 76 bytes for sending
DEBUG:telethon.network.mtprotosender:Encrypted messages put in a queue to be sent
DEBUG:telethon.network.mtprotosender:Waiting for messages to send...
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
DEBUG:telethon.network.mtprotosender:Handling bad salt for message 7410435962950057644
DEBUG:telethon.network.mtprotosender:1 message(s) will be resent
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
DEBUG:telethon.extensions.messagepacker:Assigned msg_id = 7410435963239099160 to InvokeWithLayerRequest (175b3260810)
DEBUG:telethon.network.mtprotosender:Encrypting 1 message(s) in 76 bytes for sending
DEBUG:telethon.network.mtprotosender:Encrypted messages put in a queue to be sent
DEBUG:telethon.network.mtprotosender:Waiting for messages to send...
DEBUG:telethon.extensions.messagepacker:Assigned msg_id = 7410435963249613420 to MsgsAck (175af519810)
DEBUG:telethon.network.mtprotosender:Encrypting 1 message(s) in 36 bytes for sending
DEBUG:telethon.network.mtprotosender:Encrypted messages put in a queue to be sent
DEBUG:telethon.network.mtprotosender:Waiting for messages to send...
WARNING:telethon.network.mtprotostate:Server sent a very new message with ID 7410436216796687365, ignoring (see FAQ for details)
DEBUG:telethon.network.mtprotosender:Receiving items from the network...
WARNING:telethon.network.mtprotostate:Server sent a very new message with ID 7410436216857783297, ignoring (see FAQ for details)
DEBUG:telethon.network.mtprotosender:Receiving items from the network...

Running the sync code from the readme basically, posting here for contrast.

from telethon import TelegramClient, events, sync
import logging

logging.basicConfig(level=logging.DEBUG)

api_id = 0
api_hash = '0'

client = TelegramClient('session_name', api_id, api_hash)
client.start()

Steps to reproduce:

  1. Create a venv
  2. pip install telethon
  3. python a.py
  4. Enter credentials
  5. Script ends ok
  6. python a.py
  7. Stuck with the above log

Windows 10 Python 3.11.9 Telethon 1.36.0

mortalis13 commented 1 month ago

Well , basically allowing to go forward after Server sent a very new message... makes the client to work, it seems, at least for getting messages. Just removed the return None after the message warnings are printed in network /mtprotostate.py

swagamoney commented 1 month ago

i'm currently having same issue, except im trying to run code on google cloud vm. it works perfectly on my machine, its stuck i same place as yours on vm.

Did you solve it?

Runs perfectly fine on my local machine but gets stuck on my server

gensx-x1 commented 1 month ago

Nope , I dropped it, I suspect there was an issue with Google blocking certain ips even tho I unlocked everything in firewall. I just used different server provider