PyTelegramBotAPI Expects a Proxy Mapping
Configure the synchronous Requests-based API helper with an HTTPS-to-SOCKS proxy mapping.
The synchronous PyTelegramBotAPI helper passes its proxy setting to Requests. Assign a dictionary mapping the destination scheme to the proxy URL before constructing the bot with the application’s bot_token. A host and port from the SOCKS5 proxy list can fill the shown SOCKS5 URL:
import telebot
from telebot import apihelper
apihelper.proxy = {
"https": "socks5h://proxy.example.net:1080",
}
bot = telebot.TeleBot(bot_token)
The colon between the key and value makes this a dictionary. A brace expression containing comma-separated strings creates a set, which Requests cannot use as a proxy mapping.
The https key matches the normal Telegram API destination. socks5h requests proxy-side hostname resolution and requires Requests’ SOCKS support.
apihelper.proxy is shared module-level configuration for synchronous helper calls. Set it before workers start; changing it around simultaneous bots can change another bot’s route. AsyncTeleBot has a different helper and transport.