Closed alirezaimi closed 3 years ago
Hm, today i have same error. What is this?
UPD: After restart problem gone.
Yesterday same issue +1 UTC+8 2020-02-19 18:25:52.518
i have this problem too when i run my script, it crashes after a few minutes and i have to log in again!
Possibly related: #958.
The code in the original post uses with client
and returns the value (which exits with
, which calls disconnect
).
The library should be automatically reconnecting on disconnection for the specified retry amount when creating the instance. This shows up in the logs. If it still fails after retrying, then it should raise, and it's up to the user to catch that.
If it's getting disconnected and not raising or logging, then that's a different bug, which I would appreciate a small code snippet for along with clear reproduction steps in a new issue.
Closing this one for the above reasons.
HI !!!! after 1 year and almost half(!!!!) i forgot the problem at all !! Thanks !!
2021: raise ConnectionError('Cannot send requests while disconnected') ConnectionError: Cannot send requests while disconnected
what's the solution?
2021: `raise ConnectionError('Cannot send requests while disconnected')
ConnectionError: Cannot send requests while disconnected`
Btw stay connected to not get the error :D
To resolve the ConnectionError: Cannot send requests while disconnected
Error, you need:
async def main():
await client.##any possible parameter here.
and
with client:
client.loop.run_until_complete(main())
An example script:
from telethon import TelegramClient
api_id = 'your api id'
api_hash = 'your api hash'
client = TelegramClient('anon', api_id, api_hash)
async def main():
await client.send_message('me', 'Hello, myself!')
with client:
client.loop.run_until_complete(main())
Edit: using client.
outside a function that gets looped by client.loop.run_until_complete()
will also result in ConnectionError: Cannot send requests while disconnected
I'm have same issue, solved using code below
.start()
first, use await
then wrap your code inside async
function
import asyncio
from telethon import TelegramClient
api_id = 'your api id'
api_hash = 'your api hash'
async def main():
client = TelegramClient('session', api_id, api_hash)
await client.start()
await client.send_message('me', 'Hello, myself!')
asyncio.run(main())
Hi I have problem with this kind of implementing telethon and can't find out why ?!
getting this error :
why !?