1

Python documentation states:

ssl.wrap_socket(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=CERT_NONE, ssl_version={see docs}, ca_certs=None, do_handshake_on_connect=True, suppress_ragged_eofs=True) Takes an instance sock of socket.socket, and returns an instance of ssl.SSLSocket, a subtype of socket.socket, which wraps the underlying socket in an SSL context.

But when I try to use the SSL socket's create_connection method, I receive a:

ssl_sock.create_connection(('www.google.com', 443))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SSLSocket' object has no attribute 'create_connection'
0

1 Answer 1

1

create_connection() is a function in the socket module that creates a new socket, connects it, and then returns it1. The method on socket objects is connect(), which accepts the same address tuple as create_connection():

ssl_socket.connect(("...", 443))

Unfortunately, in the documentation for the socket module, it's easy to confuse them. You need to check which part of the page you're on. Methods on socket objects are found only in the Socket Objects section, and the prefix to the methods is "socket.", meaning "a method of the socket.socket type", which turns out to be identical to the "socket." prefix for the other functions in the module, where it means "a function of the socket module".

1When the docs say "the socket", they mean the socket that was created in the function, even though they don't ever say that a socket is created.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.