I write a test bot for telegram by Pyrogram library. It work on my local but on pythonanywhere bash not work and can not connect:
INFO:pyrogram.crypto.aes:Using TgCrypto
Pyrogram v1.2.9, Copyright (C) 2017-2021 Dan <https://github.com/delivrance>
Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: [Errno 111] Connection refused
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: [Errno 111] Connection refused
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: [Errno 111] Connection refused
WARNING:pyrogram.connection.connection:Connection failed! Trying again...
INFO:pyrogram.connection.connection:Disconnected
INFO:pyrogram.session.session:Session stopped
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: [Errno 111] Connection refused
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: [Errno 111] Connection refused
INFO:pyrogram.connection.connection:Connecting...
WARNING:pyrogram.connection.connection:Unable to connect due to network issues: [Errno 111] Connection refused
Then when I press ctrl+c to stop app:
Traceback (most recent call last):
File "/home/taregh/bot.py", line 37, in <module>
client.run()
File "/home/taregh/.local/lib/python3.9/site-packages/pyrogram/methods/utilities/run.py", line 61, in run
self.start()
File "/home/taregh/.local/lib/python3.9/site-packages/pyrogram/sync.py", line 56, in async_to_sync_wrap
return loop.run_until_complete(coroutine)
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
self._run_once()
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1890, in _run_once
handle._run()
File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/home/taregh/.local/lib/python3.9/site-packages/pyrogram/methods/utilities/start.py", line 53, in start
is_authorized = await self.connect()
File "/home/taregh/.local/lib/python3.9/site-packages/pyrogram/methods/auth/connect.py", line 46, in connect
await self.session.start()
File "/home/taregh/.local/lib/python3.9/site-packages/pyrogram/session/session.py", line 127, in start
await self.connection.connect()
File "/home/taregh/.local/lib/python3.9/site-packages/pyrogram/connection/connection.py", line 57, in connect
await self.protocol.connect(self.address)
File "/home/taregh/.local/lib/python3.9/site-packages/pyrogram/connection/transport/tcp/tcp_abridged_o.py", line 40, in connect
await super().connect(address)
File "/home/taregh/.local/lib/python3.9/site-packages/pyrogram/connection/transport/tcp/tcp.py", line 82, in connect
self.socket.connect(address)
File "/usr/local/lib/python3.9/site-packages/socks.py", line 47, in wrapper
return function(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/socks.py", line 780, in connect
super(socksocket, self).connect((dest_addr, dest_port))
KeyboardInterrupt
I installed all requirements. But dose not work at all.
Unable to connect due to network issues: [Errno 111] Connection refused
Error should be quite clear. The connection is being refused.
Pythonanywhere doesn't let you use random ports and does not work with Telegram. Libraries that work via HTTP (Python-Telegram-Bot for example) should work, but Pyrogram does not.