Skip to content

Commit fe5ae8e

Browse files
committed
request.py: Fix warning on stderr irrelevant for most users
Attempting to import urllib3.contrib.socks may fail if PySocks is not installed. Most users won't care for that. Only import that module if the user requested to use a socks proxy.
1 parent 284f16b commit fe5ae8e

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

telegram/utils/request.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
import urllib3.contrib.appengine
3232
from urllib3.connection import HTTPConnection
3333
from urllib3.util.timeout import Timeout
34-
try:
35-
from urllib3.contrib.socks import SOCKSProxyManager
36-
except ImportError:
37-
SOCKSProxyManager = None
3834

3935
from telegram import (InputFile, TelegramError)
4036
from telegram.error import (Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated,
@@ -102,7 +98,9 @@ def __init__(self,
10298
else:
10399
kwargs.update(urllib3_proxy_kwargs)
104100
if proxy_url.startswith('socks'):
105-
if not SOCKSProxyManager:
101+
try:
102+
from urllib3.contrib.socks import SOCKSProxyManager
103+
except ImportError:
106104
raise RuntimeError('PySocks is missing')
107105
mgr = SOCKSProxyManager(proxy_url, **kwargs)
108106
else:

0 commit comments

Comments
 (0)