Skip to content

Commit

Permalink
Handle PySocks ProxyConnectionError
Browse files Browse the repository at this point in the history
In the presence of PySocks, httplib2 falls back on it instead of its own bundled `socks.py`. However, exception `ProxyConnectionError` produced by PySocks is a bit different that expected, it lacks `args`. An attempt to extract `errno` from it fails with `IndexError: tuple index out of range` (see httplib2#170). The patch addresses this.
  • Loading branch information
ivanyu committed Sep 25, 2021
1 parent ddd0c68 commit b64bd7a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python3/httplib2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,11 @@ def _conn_request(self, conn, request_uri, method, body, headers):
conn.close()
raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
except socket.error as e:
errno_ = e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno
errno_ = None
if len(e.args) > 0:
errno_ = e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno
elif hasattr(e, 'socket_err'):
errno_ = e.socket_err.args[0]
if errno_ in (errno.ENETUNREACH, errno.EADDRNOTAVAIL) and i < RETRIES:
continue # retry on potentially transient errors
raise
Expand Down

0 comments on commit b64bd7a

Please sign in to comment.