Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle PySocks ProxyConnectionError #202

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion python3/httplib2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ def _get_end2end_headers(response):
return [header for header in list(response.keys()) if header not in hopbyhop]


def _errno_from_exception(e):
# socket.error and common wrap in .args
if len(e.args) > 0:
return e.args[0].errno if isinstance(e.args[0], socket.error) else e.errno

# pysocks.ProxyError wraps in .socket_err
# https://github.com/httplib2/httplib2/pull/202
if hasattr(e, "socket_err"):
e_int = e.socket_err
return e_int.args[0].errno if isinstance(e_int.args[0], socket.error) else e_int.errno

return None


URI = re.compile(r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?")


Expand Down Expand Up @@ -1355,7 +1369,7 @@ 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_ = _errno_from_exception(e)
if errno_ in (errno.ENETUNREACH, errno.EADDRNOTAVAIL) and i < RETRIES:
continue # retry on potentially transient errors
raise
Expand Down