@agroshel

Где ошибка: telegram client на хостинг?

Я зарегистрировал в "API telegram client" своего клиента, написал простенький код на python + Telethon.

from telethon.sync import TelegramClient
from telethon.sessions import StringSession
from settings import (API_ID, API_HASH, SESSION_STRING)

client = TelegramClient(StringSession(SESSION_STRING), API_ID, API_HASH)

client.start()

o_sebe=client.get_me().stringify()

f=open('mess_from_teleg.txt', 'a') # сначала откроем файл на запись
f.write(o_sebe)
f.flush()  
f.close() # закроем файл после записи

settings.py - в нём API_ID, API_HASH, SESSION_STRING

Проверил работу скрипта на компьютере: работает. Захотел выложить на хостинг PythonAnywhere и Heroku. Аккаунты бесплатные. Там и там скрипт не работает.

Вот логи после запуска скрипта:
PythonAnywhere
Запускаю скрипт и в консоли вижу следующее:

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/daralt/proba6Telethon.py", line 7, in <module>
    client.start()
  File "/home/daralt/.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/daralt/.local/lib/python3.9/site-packages/telethon/client/auth.py", line 140, in _start
    await self.connect()
  File "/home/daralt/.local/lib/python3.9/site-packages/telethon/client/telegrambaseclient.py", line 513, in connect
    if not await self._sender.connect(self._connection(
  File "/home/daralt/.local/lib/python3.9/site-packages/telethon/network/mtprotosender.py", line 127, in connect
    await self._connect()
  File "/home/daralt/.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)


Heroku
После запуска в консоли вижу следующее:

2021-10-21T03:39:23.922724+00:00 app[api]: Scaled to worker@1:Free by user daralt@mail.ru
2021-10-21T03:39:26.879709+00:00 heroku[worker.1]: Starting process with command `python proba6Telethon.py`
2021-10-21T03:39:27.710377+00:00 heroku[worker.1]: State changed from starting to up
2021-10-21T03:39:28.800805+00:00 heroku[worker.1]: Process exited with status 0
2021-10-21T03:39:28.871737+00:00 heroku[worker.1]: State changed from up to crashed
2021-10-21T03:39:28.875439+00:00 heroku[worker.1]: State changed from crashed to starting
2021-10-21T03:39:31.564855+00:00 heroku[worker.1]: Starting process with command `python proba6Telethon.py`
2021-10-21T03:39:32.267858+00:00 heroku[worker.1]: State changed from starting to up
2021-10-21T03:39:33.288949+00:00 heroku[worker.1]: Process exited with status 0
2021-10-21T03:39:33.356311+00:00 heroku[worker.1]: State changed from up to crashed

В чем ошибка?
  • Вопрос задан
  • 645 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы