Telethon 机器人无法在 PythonAnywhere 上运行

Telethon bot not working on PythonAnywhere

我尝试在 PythonAnywhere 上部署我的 Telethon 机器人,但出现以下异常:

Attempt 1 at connecting failed: ConnectionRefusedError: [Errno 111] Connect call failed ('149.154.167.51', 443)
Attempt 2 at connecting failed: ConnectionRefusedError: [Errno 111] Connect call failed ('149.154.167.51', 443)
Attempt 3 at connecting failed: ConnectionRefusedError: [Errno 111] Connect call failed ('149.154.167.51', 443)
Attempt 4 at connecting failed: ConnectionRefusedError: [Errno 111] Connect call failed ('149.154.167.51', 443)
Attempt 5 at connecting failed: ConnectionRefusedError: [Errno 111] Connect call failed ('149.154.167.51', 443)
Attempt 6 at connecting failed: ConnectionRefusedError: [Errno 111] Connect call failed ('149.154.167.51', 443)
Traceback (most recent call last):
  File "/home/hellbowe/popa3/main.py", line 51, in <module>
    clientg.start(phone_tg, password_tg)
  File "/home/hellbowe/.local/lib/python3.9/site-packages/telethon/client/auth.py", line 133, in start
    else self.loop.run_until_complete(coro)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/hellbowe/.local/lib/python3.9/site-packages/telethon/client/auth.py", line 140, in _start
    await self.connect()
  File "/home/hellbowe/.local/lib/python3.9/site-packages/telethon/client/telegrambaseclient.py", line 525, in connect
    if not await self._sender.connect(self._connection(
  File "/home/hellbowe/.local/lib/python3.9/site-packages/telethon/network/mtprotosender.py", line 127, in connect
    await self._connect()
  File "/home/hellbowe/.local/lib/python3.9/site-packages/telethon/network/mtprotosender.py", line 253, in _connect
    raise ConnectionError('Connection to Telegram failed {} time(s)'.format(self._retries))
ConnectionError: Connection to Telegram failed 5 time(s)

它在我的设备上运行良好。

我试图将代理添加到 TelegramClient() 东西但是得到了这个:

Traceback (most recent call last):
  File "/home/hellbowe/popa3/main.py", line 51, in <module>
    clientg = TelegramClient('popa3', api_id_tg, api_hash_tg, proxy = ('http', '***', 80))
  File "/home/hellbowe/.local/lib/python3.9/site-packages/telethon/client/telegrambaseclient.py", line 292, in __init__
    session.set_dc(
  File "/home/hellbowe/.local/lib/python3.9/site-packages/telethon/sessions/sqlite.py", line 168, in set_dc
    self._update_session_table()
  File "/home/hellbowe/.local/lib/python3.9/site-packages/telethon/sessions/sqlite.py", line 194, in _update_session_table
    c.execute('delete from sessions')
sqlite3.OperationalError: database is locked

您有一些其他进程锁定了您的 sqlite 数据库(或数据库已损坏)尝试删除数据库文件或将其移动到其他地方以便重新创建它。

据我所知,您需要登录 Telegram 才能使用 telethon。在您的机器中,您可以使用命令行界面执行此操作,但在托管中则不能。我在租用虚拟服务器时解决了这个问题,我可以在其中登录 Telegram。然后我只是 运行 python 带有一些选项的脚本,以便始终工作