proxy connection fix #2

This commit is contained in:
Dmitry Bukhta 2018-02-20 17:55:14 +03:00
parent 9e08d5b735
commit 937523419d

View File

@ -9,6 +9,11 @@ from datetime import timedelta
from io import BytesIO, BufferedWriter
from threading import Lock
try:
import socks
except ImportError:
socks = None
MAX_TIMEOUT = 15 # in seconds
CONN_RESET_ERRNOS = {
errno.EBADF, errno.ENOTSOCK, errno.ENETUNREACH,
@ -70,9 +75,10 @@ class TcpClient:
self._socket.connect(address)
break # Successful connection, stop retrying to connect
except ProxyConnectionError:
raise
except OSError as e:
# Stop retrying to connect if proxy connection error occurred
if socks and isinstance(e, socks.ProxyConnectionError):
raise
# There are some errors that we know how to handle, and
# the loop will allow us to retry
if e.errno in (errno.EBADF, errno.ENOTSOCK, errno.EINVAL,