This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ssl.SSLError has errno value of None
Type: behavior Stage:
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Paul.Wiseman, pitrou
Priority: normal Keywords:

Created on 2013-04-08 15:36 by Paul.Wiseman, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg186310 - (view) Author: Paul Wiseman (Paul.Wiseman) Date: 2013-04-08 15:35
I was using py2.7.3 and was getting None back for the errno attribute for an ssl.SSLError('The read operation timed out').

I noticed in the 2.7.4 release notes that it sounds like there was a fix for this:

Issue #12065: connect_ex() on an SSL socket now returns the original errno
when the socket's timeout expires (it used to return None).

I've just tested in py2.7.4 and I'm still getting None back for the errno attribute.

I'm using this code to produce the error:

import requests

def __init__(self, exception):
    # First extract the real underlying exception
    exception = exception.args[0]  # This should be ssl.SSLError
    super(requests.exceptions.ConnectionError, self).__init__(exception)
    self.strerror = exception.strerror
    self.errno = exception.errno

requests.exceptions.ConnectionError.__init__ = __init__

timeout_val = 0.2
while True:
    try:
        print requests.get("https://google.com", timeout=timeout_val)
    except requests.exceptions.SSLError as err:
        print err.strerror
        print err.errno
        break
    except Exception as err:
        print "Got %s: %s" % (err.__class__.__name__, err)
    timeout_val /= 2
msg186321 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-08 18:10
The issue you mention is unrelated. connect_ex() returns an error code, it doesn't raise an exception.

As for the errno attribute being None, this is because most SSLErrors don't correspond to a single OS error. And in the case you mention ("the read operation timed out"), it isn't an OS error at all: it's simply a select() call timing out.
msg186350 - (view) Author: Paul Wiseman (Paul.Wiseman) Date: 2013-04-08 21:22
Ah ok, thanks for clearing that up. I thought there'd have been a socket.error with ETIMEDOUT raised as the underlying exception, similar to if it times out during the non-ssl part of the request
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 61864
2013-04-08 21:22:16Paul.Wisemansetmessages: + msg186350
2013-04-08 18:10:10pitrousetstatus: open -> closed

nosy: + pitrou
messages: + msg186321

resolution: not a bug
2013-04-08 15:36:00Paul.Wisemancreate