[issue27629] Cannot create raw ssl.SSLSocket

nemunaire report at bugs.python.org
Tue Jul 26 19:21:45 EDT 2016


New submission from nemunaire:

I got this stacktrace:
  File "test_ssl.py", line 3, in <module>
    sock = ssl.SSLSocket(server_hostname="docs.python.org")
  File "/usr/lib/python3.4/ssl.py", line 536, in __init__
    if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
AttributeError: 'NoneType' object has no attribute 'getsockopt'

with this minimal code:
import ssl

sock = ssl.SSLSocket(server_hostname="docs.python.org")
sock.connect(("docs.python.org", 443))
sock.sendall(b"GET /3/library/ssl.html HTTP/1.0\r\nHost: docs.python.org\r\n\r\n")
print(sock.recv(4096).decode())

Whereas the None socket is correctly handled a few lines later: https://hg.python.org/cpython/file/tip/Lib/ssl.py#l715

All Python >= 3.3 are affected (since https://hg.python.org/cpython/rev/a00842b783cf) and can be patched with the same file, attached to this issue.

----------
components: Library (Lib)
files: fix_sslsocket_init_without_socket_3.3-3_6.patch
keywords: patch
messages: 271419
nosy: nemunaire
priority: normal
severity: normal
status: open
title: Cannot create raw ssl.SSLSocket
type: behavior
versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file43900/fix_sslsocket_init_without_socket_3.3-3_6.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27629>
_______________________________________


More information about the Python-bugs-list mailing list