Issue 19057: Sometimes urllib2 raises URLError when trying POST with httpS (original) (raw)

Trying to use POST-request to https://vk.com and sometimes library raise an error. File "library/vkApi.py", line 31, in post response = self.Opener.open(request) File "/usr/lib/python2.7/urllib2.py", line 404, in open response = self._open(req, data) File "/usr/lib/python2.7/urllib2.py", line 422, in _open '_open', req) File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open return self.do_open(httplib.HTTPSConnection, req) File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open raise URLError(err) URLError:

This exception appears randomly, connection is ok 100%. I tried it on different machines with python 2.7.4 and 2.7.3.

I would guess that if you did a network trace you'd find out there really was a packet that did not arrive (a timeout). Note that detecting this is complicated by the fact that ssl is involved. (I don't know the details, but I remember someone saying that more than one packet may be involved in something that looks like a single event at the OpenSSL level.)

It is certainly possible that there is a bug at the OpenSSL or (less likely) the _ssl module level, but the first step in debugging it would be to get that network trace, I think...

As I said, though, I'm not an expert in this area, perhaps someone who is will have other suggestions.