Answer the question
In order to leave comments, you need to log in
How to run a telegram bot from behind a proxy?
I teach at MSTU. Bauman and my students write bots on laboratory telegrams. Due to the blocking of the telegram, we have problems. We use the PyCharm environment and the pyTelegramBotAPI library. I'm trying to start a bot from behind a proxy like so:
import telebot
from telebot import apihelper
apihelper.proxy = {'http':'http://x.x.x.x:port'}
TOKEN = ''
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=['start'])
def start(m):
msg = bot.send_message(m.chat.id, 'Привет!' )
bot.polling()
ERROR - TeleBot: "ConnectTimeout occurred, args=(MaxRetryError("HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot547971947:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x02A022F0>, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))",),)
Answer the question
In order to leave comments, you need to log in
https://github.com/eternnoir/pyTelegramBotAPI#proxy
documentation:
but if it doesn't work, try:
Found here
Install the latest gunicorn, PySocks, pyTelegramBotAPI, requests and urllib3 libraries
Then try another proxy like this one
ip = '195.201.137.246'
port = '1080'
apihelper.proxy = {
'https': 'socks5://{}:{}'.format(ip,port)
}
I have already spent a lot of time trying to figure out a similar problem. Faced on the ninth Debian, either updated to the latest versions.
In order to radically exclude the version with old libs (you never know, this is Debian, the lib versions are behind), I checked it on a freshly installed Ubuntu server, version 17, specially for this purpose.
Attempts to find the answer to the question in Google, or the corresponding telegram groups, did not give anything.
As a result, I switched to this bot https://github.com/python-telegram-bot/python-tele...
Here's how to configure it to work through a proxy https://github.com/python-telegram-bot/python-tele ...
And if the proxy is with authorization, only the first method worked for me.
By the way, this bot is more popular than telebot in terms of the number of stars, although the differences between them are not entirely clear to me. Telebot uses decorators, the code is more concise and more beautiful.
Sorry for offtopic, I solved the problem by switching to another library - "telepot"
import telepot
basic_auth = ('username', 'password')
SetProxy = telepot.api.set_proxy("http://10.10.10.10:1080", basic_auth)
bot = telepot.Bot('11111111:xxxxxxxxxxxxxxxxxxxxxxxxxxxx')
print(bot.getMe())
There was the same error, I downloaded the application on the WindScribe PC, tried it from Western Canada, everything works. https://windscribe.com/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question