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 #170). The patch addresses this.
  • Loading branch information
ivanyu committed Sep 25, 2021
1 parent ddd0c68 commit f0ca992
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.PHONY: tests

tests:
-cd python2 && python2.4 httplib2test.py
-cd python2 && python2.5 httplib2test.py
-cd python2 && python2.6 httplib2test.py
-cd python2 && python2.6 httplib2test_appengine.py
cd python2 && python2.7 httplib2test.py
cd python2 && python2.7 httplib2test_appengine.py
# -cd python2 && python2.4 httplib2test.py
# -cd python2 && python2.5 httplib2test.py
# -cd python2 && python2.6 httplib2test.py
# -cd python2 && python2.6 httplib2test_appengine.py
# cd python2 && python2.7 httplib2test.py
# cd python2 && python2.7 httplib2test_appengine.py
cd python3 && python3 httplib2test.py

VERSION = $(shell python setup.py --version)
Expand Down
7 changes: 6 additions & 1 deletion python3/httplib2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,12 @@ 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'):
e_int = e.socket_err
errno_ = e_int.args[0].errno if isinstance(e_int.args[0], socket.error) else e_int.errno
if errno_ in (errno.ENETUNREACH, errno.EADDRNOTAVAIL) and i < RETRIES:
continue # retry on potentially transient errors
raise
Expand Down
10 changes: 10 additions & 0 deletions python3/myrun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import httplib2

http = httplib2.Http()
http.proxy_info = httplib2.ProxyInfo(
httplib2.socks.PROXY_TYPE_HTTP,
"localhost",
5050,
)
r = http.request("https://google.com")
print(r)

0 comments on commit f0ca992

Please sign in to comment.