Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throws CancelledError, when I try to use Session File from one device to another #4104

Closed
glockOwner opened this issue May 8, 2023 · 1 comment

Comments

@glockOwner
Copy link

I tryed to login and do some actions with telethon on my device. Telethon created session file, code worked fine. Then I moved this code and session file into my hosting provider's server. The CancelledError throws on this server.

There is my code:
from telethon import TelegramClient

Use your own values from my.telegram.org

api_id = *********
api_hash = '********************************'

The first parameter is the .session file name (absolute paths allowed)

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

async def main():
await client.send_message('***********', 'SESSIONTEST')

with client:
client.loop.run_until_complete(main())

And error traceback:

Unexpected exception in the receive loop
Traceback (most recent call last):
File "/home/i/ivashk1f/.local/lib/python3.6/site-packages/telethon/network/connection/connection.py", line 332, in _recv_loop
data = await self._recv()
File "/home/i/ivashk1f/.local/lib/python3.6/site-packages/telethon/network/connection/connection.py", line 369, in _recv
return await self._codec.read_packet(self._reader)
File "/home/i/ivashk1f/.local/lib/python3.6/site-packages/telethon/network/connection/tcpfull.py", line 25, in read_packet
packet_len_seq = await reader.readexactly(8) # 4 and 4
File "/usr/lib/python3.6/asyncio/streams.py", line 674, in readexactly
yield from self._wait_for_data('readexactly')
File "/usr/lib/python3.6/asyncio/streams.py", line 464, in _wait_for_data
yield from self._waiter
concurrent.futures._base.CancelledError
Unhandled error while receiving data
Traceback (most recent call last):
File "/home/i/ivashk1f/.local/lib/python3.6/site-packages/telethon/network/mtprotosender.py", line 505, in _recv_loop
body = await self._connection.recv()
File "/home/i/ivashk1f/.local/lib/python3.6/site-packages/telethon/network/connection/connection.py", line 301, in recv
raise err
File "/home/i/ivashk1f/.local/lib/python3.6/site-packages/telethon/network/connection/connection.py", line 332, in _recv_loop
data = await self._recv()
File "/home/i/ivashk1f/.local/lib/python3.6/site-packages/telethon/network/connection/connection.py", line 369, in _recv
return await self._codec.read_packet(self._reader)
File "/home/i/ivashk1f/.local/lib/python3.6/site-packages/telethon/network/connection/tcpfull.py", line 25, in read_packet
packet_len_seq = await reader.readexactly(8) # 4 and 4
File "/usr/lib/python3.6/asyncio/streams.py", line 674, in readexactly
yield from self._wait_for_data('readexactly')
File "/usr/lib/python3.6/asyncio/streams.py", line 464, in _wait_for_data
yield from self._waiter
concurrent.futures._base.CancelledError

@Lonami Lonami closed this as completed in 6a7a981 May 8, 2023
@Lonami
Copy link
Member

Lonami commented May 8, 2023

While "Unhandled error while receiving data" was a bug (solved by the above commit), the behavior should've been essentially the same.

If a disconnection occur it will exit.

I don't know why your provider disconnects the library but it's unlikely to be a problem with the library's code. Maybe the above fix will uncover the real cause.

Jisan09 added a commit to TgCatUB/Telethon that referenced this issue May 28, 2023
* except and propagate TypeNotFoundError during update handling

* Better document breaking ToS will lead to bans

Closes LonamiWebs#4102.

* Fix KeyError when ID is in cache but queried without mark

Closes LonamiWebs#4084.

* Fix asyncio.CancelledError was being swallowed by inner except

Closes LonamiWebs#4104.

* Add check for asyncio event loop to remain the same

* Update FAQ with more common questions

---------

Co-authored-by: Lonami Exo <totufals@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants