I'm trying to get every new message sent in a channel with python and then use the data to do some further processing. This is my code:
api_id = *******
api_hash = '**********************'
client = TelegramClient(
'session_name',
api_id,
api_hash,
)
client.start()
print(client.get_me().stringify())
client.send_message('someone', 'Hello! Talking to you from Telethon')
And this is the error that I get:
C:\Users\erfan\AppData\Local\Programs\Python\Python39\python.exe "C:/Users/erfan/Desktop/Boors py/main.py"
Traceback (most recent call last):
File "C:\Users\erfan\Desktop\Boors py\main.py", line 14, in <module>
client.start()
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\auth.py", line 133, in start
else self.loop.run_until_complete(coro)
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\auth.py", line 140, in _start
await self.connect()
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 516, in connect
if not await self._sender.connect(self._connection(
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\network\mtprotosender.py", line 123, in connect
await self._connect()
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\network\mtprotosender.py", line 249, in _connect
raise ConnectionError('Connection to Telegram failed {} time(s)'.format(self._retries))
ConnectionError: Connection to Telegram failed 5 time(s)
Process finished with exit code 1
Telegram is blocked by my country. So I use Lantern to have access to it and I can access web.telegram.com. I also tried using a mtproxy but got the same error.