0

The application works fine on my PC. No timeouts. When I turned it off to move it to my server, at first after logging into the session with phone number, password, and login code, this error appeared:

telethon.errors.rpcerrorlist.FloodWaitError: A wait of 31387 seconds is required (caused by ResolveUsernameRequest)

on line

client.get_messages(channel_name, ids=141)

I waited way longer than the ~8+ hours.

My PC program was working fine. I again stopped it and opened the same script on my server.

Now the wait is doubled:

telethon.errors.rpcerrorlist.FloodWaitError: A wait of 67203 seconds is required (caused by ResolveUsernameRequest)

on same line. Unusable.

This is MY OWN channel owned by the very account I sign in to that I'm getting the message from...

tommy1213
  • 93
  • 1
  • 5

1 Answers1

1

Your question title mentions you "can't login", but your question body seems to indicate otherwise. I will assume your problem is what's described in the question's body.

Telethon will use the .session file as a cache, containing, among other things, usernames and their corresponding id and access_hash. Both of these values are required to use a chat as a parameter for the API requests.

If the username is not in cache, the library will need to fetch it first. This fetching has a high flood wait, and there's no way to bypass that.

The correct approach here would be to:

print(await client.get_input_entity(channel_name))

once, and then hardcode the output in your script, like so:

from telethon import types

CHANNEL = types.InputPeerChannel(channel_id=..., access_hash=...)

(You can use a different mechanism to store it persistently. Hardcoding it is just the simplest way to do it.)

And then you can use CHANNEL instead of channel_name.

Lonami
  • 5,945
  • 2
  • 20
  • 38
  • Error: `'TelegramClient' object has no attribute 'get_input_peer'` If I use `telethon.utils.get_input_peer()` as I found in docs, this exception happens: `telethon/utils.py", line 176, in get_input_peer if entity.SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer') AttributeError: 'str' object has no attribute 'SUBCLASS_OF_ID' ` and `telethon/utils.py", line 138, in _raise_cast_fail raise TypeError('Cannot cast {} to any kind of {}.'.format( TypeError: Cannot cast str to any kind of InputPeer. ` I guess this means I need to feed it the Channel Entity? I'll try in... 51000 s – tommy1213 Mar 09 '23 at 18:57
  • 1
    Sorry, I meant `get_input_entity` -- I've updated the answer. – Lonami Mar 09 '23 at 19:02
  • Thank you, the issue with initial timeout got resolved, the connection is smooth and I can obtain the message to forward. I'm getting timeouts on forwarding now though, and while PC scripts' waits are elastic (only if a chat has a timeout set) the server script gets unified (as if device-linked) timeout, now of 14 hours on all chats. I can do it on PC still. No idea why though, should I open a new issue? – tommy1213 Mar 09 '23 at 20:14
  • If you're still getting a `FloodWaitError` caused by `ResolveUsernameRequest`, you're still using usernames somewhere. You can fix those in the same way. If you're getting `FloodWaitError` caused by `SendMessageRequest`, there's nothing you can do except slow down. – Lonami Mar 09 '23 at 22:23
  • https://stackoverflow.com/a/75656496/ contains even more details. – Lonami Mar 10 '23 at 17:22