E
E
EkS20192019-11-03 23:26:06
Python
EkS2019, 2019-11-03 23:26:06

How to connect a bot through a proxy in python to telegrams?

I am learning how to write a bot for telegrams in python and ran into a problem that I need to connect a proxy. Tell me how to connect a proxy to send a message to the bot?

from telebot import apihelper
import telebot

token = 'xxx'

apihelper.proxy = {'https':'https://88.204.154.155:8080'}


bot = telebot.TeleBot(token)

@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Привет, ты написал мне /start')

@bot.message_handler(content_types=['text'])
def send_text(message):
    if message.text.lower() == 'привет':
        bot.send_message(message.chat.id, 'Привет, мой создатель')
    elif message.text.lower() == 'пока':
        bot.send_message(message.chat.id, 'Прощай, создатель')

bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SuckMyPython, 2019-12-20
@SuckMyPython

Infa 100% this method works with a private proxy:
import telebot
from telebot import apihelper
TOKEN = '0000000:xxxxxxxxxxxxxxxxxxxxxxx'
PROXY = 'login:[email protected]:port' #(Login and password from the purchased proxy)
apihelper.proxy = {'https ':'socks5://' + PROXY}
bot = telebot.TeleBot(TOKEN)
=====================
PS If it gives an error sometimes it helps instead of 'socks5 ://' replace with 'socks5h://'
And most importantly - the proxy must be converted to the type "SOCKS5" (done in the proxy admin panel, at least on proxy6.net), the bot will not work through the type "HTTPS" .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question