Author ddvoinikov
Recipients ddvoinikov
Date 2008-10-22.11:37:21
SpamBayes Score 1.45596e-06
Marked as misclassified No
Message-id <>
If I connect a TCP socket s using regular s.connect(), then wrap it
using ssl.wrap_socket(s) and call do_handshake on the resulting SSL
socket, handshake fails in with 

AttributeError: 'NoneType' object has no attribute 'do_handshake'

The problem is that when TCP socket is being wrapped in, it
is not recognized as connected by a call to getpeername(), the exception
thrown in and silenced is this:

[Errno 10057] A request to send or receive data was disallowed because
the socket is not connected and (when sending on a datagram socket using
a sendto call) no address was supplied

This is awkward, because synchronous s.connect() has just returned
successfully. Even more weird, if I insert s.getpeername() between TCP
connect() and SSL do_handshake() the latter works fine.

Here is a working sample:


from socket import socket, AF_INET, SOCK_STREAM
from ssl import wrap_socket, PROTOCOL_TLSv1, CERT_NONE

def test_handshake(address, WORKAROUND):

    s = socket(AF_INET, SOCK_STREAM)


    ssl = wrap_socket(s, server_side = False,
                      ssl_version = PROTOCOL_TLSv1,
                      cert_reqs = CERT_NONE,
                      do_handshake_on_connect = False)

address = ("", 443)

test_handshake(address, True) # with workaround
print("worked so far")
test_handshake(address, False)
print("but not here it didn't")


I'm using Python 3.0rc1 under Windows.
Date User Action Args
2008-10-22 11:37:24ddvoinikovsetrecipients: + ddvoinikov
2008-10-22 11:37:24ddvoinikovsetmessageid: <>
2008-10-22 11:37:22ddvoinikovlinkissue4171 messages
2008-10-22 11:37:21ddvoinikovcreate