Не могу соединиться на хостинге python
Спасибо за внимание, вообщем есть такой код:
<pre>import socket
import socks
import configparser
import json
from telethon.sync import TelegramClient
from telethon import connection
# для корректного переноса времени сообщений в json
from datetime import date, datetime
# классы для работы с каналами
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch
# класс для работы с сообщениями
from telethon.tl.functions.messages import GetHistoryRequest
# Присваиваем значения внутренним переменным
api_id = ''
api_hash = ''
username = ''
proxy = (socks.set_default_proxy, "151.232.18.66", "5678")
socket.socket = socks.socksocket
client = TelegramClient(username, api_id, api_hash)
client.start()
async def dump_all_messages(channel):
'''Записывает json-файл с информацией о всех сообщениях канала/чата'''
offset_msg = 0 # номер записи, с которой начинается считывание
limit_msg = 100 # максимальное число записей, передаваемых за один раз
all_messages = [] # список всех сообщений
total_messages = 0
total_count_limit = 0 # поменяйте это значение, если вам нужны не все сообщения
class DateTimeEncoder(json.JSONEncoder):
'''Класс для сериализации записи дат в JSON'''
def default(self, o):
if isinstance(o, datetime):
return o.isoformat()
if isinstance(o, bytes):
return list(o)
return json.JSONEncoder.default(self, o)
while True:
history = await client(GetHistoryRequest(
peer=channel,
offset_id=offset_msg,
offset_date=None, add_offset=0,
limit=limit_msg, max_id=0, min_id=0,
hash=0))
if not history.messages:
break
messages = history.messages
for message in messages:
all_messages.append(message.to_dict())
offset_msg = messages[len(messages) - 1].id
total_messages = len(all_messages)
if total_count_limit != 0 and total_messages >= total_count_limit:
break
with open('channel_messages.json', 'w', encoding='utf8') as outfile:
json.dump(all_messages, outfile, indent=4, ensure_ascii=False, cls=DateTimeEncoder)
async def main(url):
channel = await client.get_entity(url)
await dump_all_messages(channel)
with client:
client.loop.run_until_complete(main("t.me/CommentTops"))</pre>
Этот код создает файл.Json с историей сообщений вот он работает когда я запускаю на ПК, но когда я запускаю его на бесплатном хостинге pythonanywhere то он выдает ошибку что не получается соединиться как решить?
Attempt 1 at connecting failed: ConnectionRefusedError: [Errno 111] Connection refused
Attempt 2 at connecting failed: ConnectionRefusedError: [Errno 111] Connection refused
Attempt 3 at connecting failed: ConnectionRefusedError: [Errno 111] Connection refused
Attempt 4 at connecting failed: ConnectionRefusedError: [Errno 111] Connection refused
Attempt 5 at connecting failed: ConnectionRefusedError: [Errno 111] Connection refused
Attempt 6 at connecting failed: ConnectionRefusedError: [Errno 111] Connection refused
Traceback (most recent call last):
File "/home/nigga22nd/bot/telegram_parsing.py", line 29, in
client.start()
File "/home/nigga22nd/.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/nigga22nd/.local/lib/python3.9/site-packages/telethon/client/auth.py", line 140, in _start
await self.connect()
File "/home/nigga22nd/.local/lib/python3.9/site-packages/telethon/client/telegrambaseclient.py", line 525, in connect
if not await self._sender.connect(self._connection(
File "/home/nigga22nd/.local/lib/python3.9/site-packages/telethon/network/mtprotosender.py", line 127, in connect
await self._connect()
File "/home/nigga22nd/.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)
вот ошибка с pythonanywhere как решить?