socket.send(), OSError(), TimeoutError(), Connection lost/reset, …#

Such network related issues are most likely a result of a temporarily slow or inconsistent network connection and will eventually disappear automatically. Other reasons include running too many clients at once or blocking the event loop for too long.

You can consider the following:

  • Make sure you are running the latest Pyrogram version

  • Install and use Speedups to speed-up Pyrogram.

  • Use Pyrogram asynchronously in its intended way.

  • Use shorter non-asynchronous processing loops.

  • Use asyncio.sleep() instead of time.sleep().

  • Use multiple threads/processes to run multiple clients.

  • Use a stable network connection.