@w1zard11830

Как решить ошибку при использовании бесплатного прокси сервера к выгрузке телеграм бота на хостинге Python Anywhere?

Приветствую!
Пытался выгрузить Телеграм бота Aiogram на бесплатный хостинг для питон проектов PythonAnywhere. В документации сказано что необходим прокси сервер чтобы выгрузить бота туда.

Раньше не сталкивался с использованием прокси поэтому не могу понять как мне в коде использовать бесплатные прокси сервера из листа прокси серверов free-proxy-list. В интернете прочёл что достаточно из списка выбрать несколько IP и порт и вписать в таком виде в код:

"from aiogram import Bot, Dispatcher, executor, types
import requests
import json

from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.types import ParseMode
from aiogram.utils import executor

В списке нашёл такой IP и порт:
proxy_ip = '185.125.253.129'
proxy_port = 8080

proxy_url = f'http://{proxy_ip}:{proxy_port}'
bot = Bot(token = "token", proxy=proxy_url)
dp = Dispatcher(bot, storage=MemoryStorage())
APIs = "weather_api"


class MyStatesGroup(StatesGroup):
STATE_1 = State()

@dp.message_handler(commands=["start"], state="*")
async def start(message: types.Message):
markup = types.ReplyKeyboardMarkup(row_width=2)
markup.add(types.KeyboardButton("Search weather"))
markup.add(types.KeyboardButton("Check other Telegram Bot examples:"))
markup.add(types.KeyboardButton("About the author"))
markup.add(types.KeyboardButton("About the Bot"))
await message.answer(f'Hello! Glad to see you {message.from_user.username}')
await message.answer(f'I am a bot created in order to demonstrate the opportunities and skills of beginner developer Uranbek Anarbaev. \n Choose one of the buttons on the keyboard:', reply_markup=markup)

@dp.message_handler(content_types=["text"])
async def check(message: types.Message):
if message.text == "Search weather":
await message.reply("Okay, send me your city name:")
await MyStatesGroup.STATE_1.set()
elif message.text == "Check other Telegram Bot examples:":
markup = types.InlineKeyboardMarkup(row_width=1)
markup.add(types.InlineKeyboardButton("Currency bot", url="https://t.me/urancurrency_bot"))
markup.add(types.InlineKeyboardButton("Weather bot", url="https://t.me/uranweather_bot"))
markup.add(types.InlineKeyboardButton("McDonalds menu bot", url="https://t.me/uranmcdonalds_bot"))
await message.answer("If you are interested in other bots by the creator, you might be interested in the following ones:", reply_markup=markup)
elif message.text == "About the author":
await about_author(message)
elif message.text == "About the Bot":
await about_bot(message)

@dp.message_handler(content_types=["text"], state=MyStatesGroup.STATE_1)
async def get_weather(message: types.Message, state: FSMContext):
city = message.text.lower().strip()
res = requests.get(f'https://api.openweathermap.org/data/2.5/weather?q=...')
data = json.loads(res.text)
await message.reply(f'Currently in {city} there is:\n - Temperature: {data["main"]["temp"]} \n - Wind speed {data["wind"]["speed"]}')
await state.finish()

async def about_author(message: types.Message):
await message.answer("Author name is Uranbek Anarbaev. He is a beginner programmer, studying at TSI AUCA in Bishkek, Kyrgyzstan.")

async def about_bot(message: types.Message):
await message.answer("Bot is a weather bot designed to help users know the current weather in their city, including temperature and wind.")

executor.start_polling(dp, skip_updates=True)

Однако в результате выдаёт такую ошибку:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/uran1337/telegram_bot.py", line 69, in
executor.start_polling(dp, skip_updates=True)
File "/home/uran1337/.local/lib/python3.10/site-packages/aiogram/utils/executor.py", line 45, in start_polling
executor.start_polling(
File "/home/uran1337/.local/lib/python3.10/site-packages/aiogram/utils/executor.py", line 320, in start_polling
loop.run_until_complete(self._startup_polling())
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "/home/uran1337/.local/lib/python3.10/site-packages/aiogram/utils/executor.py", line 372, in _startup_polling
await self._welcome()
File "/home/uran1337/.local/lib/python3.10/site-packages/aiogram/utils/executor.py", line 361, in _welcome
user = await self.dispatcher.bot.me
File "/home/uran1337/.local/lib/python3.10/site-packages/aiogram/bot/bot.py", line 30, in me
setattr(self, '_me', await self.get_me())
File "/home/uran1337/.local/lib/python3.10/site-packages/aiogram/bot/bot.py", line 233, in get_me
result = await self.request(api.Methods.GET_ME, payload)
File "/home/uran1337/.local/lib/python3.10/site-packages/aiogram/bot/base.py", line 236, in request
return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
File "/home/uran1337/.local/lib/python3.10/site-packages/aiogram/bot/api.py", line 142, in make_request
raise exceptions.NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
aiogram.utils.exceptions.NetworkError: Aiohttp client throws an error: ClientProxyConnectionError: Cannot connect to host 185.125.253.129:8080 ssl:default [Connect c
all failed ('185.125.253.129', 8080)]

Что делать?
  • Вопрос задан
  • 120 просмотров
Пригласить эксперта
Ответы на вопрос 1
SoreMix
@SoreMix
yellow
Прокси используются от самого pythonanywhere:
https://help.pythonanywhere.com/pages/403Forbidden...

bot = Bot(token = "token", proxy='http://proxy.server:3128')
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы