mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-22 07:06:26 +01:00
Add support for Socks5 proxy. (#518)
This commit is contained in:
parent
0507378509
commit
e39afad321
2 changed files with 15 additions and 5 deletions
1
setup.py
1
setup.py
|
@ -36,6 +36,7 @@ with codecs.open('README.rst', 'r', 'utf-8') as fd:
|
|||
install_requires=requirements(),
|
||||
extras_require={
|
||||
'json': 'ujson',
|
||||
'socks': 'PySocks'
|
||||
},
|
||||
include_package_data=True,
|
||||
classifiers=[
|
||||
|
|
|
@ -30,6 +30,10 @@ import certifi
|
|||
import urllib3
|
||||
from urllib3.connection import HTTPConnection
|
||||
from urllib3.util.timeout import Timeout
|
||||
try:
|
||||
from urllib3.contrib.socks import SOCKSProxyManager
|
||||
except ImportError:
|
||||
SOCKSProxyManager = None
|
||||
|
||||
from telegram import (InputFile, TelegramError)
|
||||
from telegram.error import (Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated,
|
||||
|
@ -92,6 +96,11 @@ class Request(object):
|
|||
mgr = urllib3.PoolManager(**kwargs)
|
||||
else:
|
||||
kwargs.update(urllib3_proxy_kwargs)
|
||||
if proxy_url.startswith('socks'):
|
||||
if not SOCKSProxyManager:
|
||||
raise RuntimeError('PySocks is missing')
|
||||
mgr = SOCKSProxyManager(proxy_url, **kwargs)
|
||||
else:
|
||||
mgr = urllib3.proxy_from_url(proxy_url, **kwargs)
|
||||
if mgr.proxy.auth:
|
||||
# TODO: what about other auth types?
|
||||
|
|
Loading…
Reference in a new issue