Snippets: Python: Make HTTP Requests via Socks5 Proxy

 20th August 2020 at 2:19pm

requests:

import requests

proxies = {
    'http': 'socks5h://user:pass@host:port',
    'https': 'socks5h://user:pass@host:port'
}
requests.post(url, proxies=proxies)

python-telegram-bot:

import telegram
from telegram.utils.request import Request
from telegram.ext import Updater

# bot 发消息的脚本
bot = telegram.Bot(token='token', request=Request(proxy_url='socks5h://user:pass@host:port'))
bot.send_message(chat_id='chat_id', text='hello')

# bot 服务
updater = Updater(token='token', request_kwargs={'proxy_url': 'socks5h://user:pass@host:port'})

See Also