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

Fix PY2 regression in connect() error handling. #150

Merged
merged 4 commits into from Nov 13, 2019
Merged
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions python2/httplib2/__init__.py
Expand Up @@ -1176,7 +1176,9 @@ def connect(self):

host = self.host
port = self.port


socket_err = None

for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
Expand Down Expand Up @@ -1218,7 +1220,8 @@ def connect(self):
self.sock.connect((self.host, self.port) + sa[2:])
else:
self.sock.connect(sa)
except socket.error as msg:
except socket.error as e:
socket_err = e
if self.debuglevel > 0:
print("connect fail: (%s, %s)" % (self.host, self.port))
if use_proxy:
Expand All @@ -1241,7 +1244,7 @@ def connect(self):
continue
break
if not self.sock:
raise socket.error(msg)
raise socket_err if socket_err else socket.error(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise a or b would work too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even better, thanks!



class HTTPSConnectionWithTimeout(httplib.HTTPSConnection):
Expand Down