A
A
agroshel2021-10-21 09:10:40
Python
agroshel, 2021-10-21 09:10:40

Where is the error: telegram client for hosting?

Hey! Help a beginner.
I registered my client in the "API telegram client", wrote a simple code in 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 - it contains API_ID, API_HASH, SESSION_STRING

I checked the script on the computer: it works. I wanted to host PythonAnywhere and Heroku. Accounts are free. Here and there the script does not work.
Here are the logs after running the script:

PythonAnywhere

I run the script and see the following in the console:

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
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

After starting, I see the following in the console:
2021-10-21T03:39:23.922724+00:00 app[api]: Scaled to [email protected]:Free by user [email protected]
2021-10-21T03:39:26.879709+00 :00 heroku[worker.1]: Starting process with command `
python
proba6Telethon.py` :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 py`
2021-10-21T03:39:32.267858+00:00 heroku[worker.1]: State changed from starting to
up 0
2021-10-21T03:39:33.356311+00:00 heroku[worker.1]: State changed from up to crashed

Can you tell me what is wrong?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question