Reputation: 4714
I'm creating a very simple example on OSX with python 2.6 but I keep getting:
Traceback (most recent call last):
File "ssl.py", line 1, in <module>
import socket, ssl
File "/Users/Dennis/ssl.py", line 5, in <module>
sslSocket = ssl.wrap_socket(s)
AttributeError: 'module' object has no attribute 'wrap_socket'
Code:
import socket, ssl
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('irc.freenode.net', 7000))
sslSocket = ssl.wrap_socket(s)
print repr(sslSocket.server())
print repr(sslSocket.issuer())
sslSocket.write('Hello secure socket\n')
s.close()
What am I doing terribly wrong?
Upvotes: 4
Views: 22112
Reputation: 23142
If you didn't name your own script ssl.py
and use Python 3.12 or newer, this is expected:
Remove the
ssl.wrap_socket()
function, deprecated in Python 3.7: instead, create assl.SSLContext
object and call itsssl.SSLContext.wrap_socket
method. Any package that still usesssl.wrap_socket()
is broken and insecure.
Source: https://docs.python.org/3.12/whatsnew/3.12.html#ssl
Upvotes: 2
Reputation: 131577
Your script is : ssl.py
When you do an import ssl
, it calls itself and that is why you get the AttributeError
Give another name to your script and it should work.
Upvotes: 5
Reputation: 70021
Don't name your script ssl.py
, because when you name your script ssl.py
and you do import ssl
you're importing this same script .
Upvotes: 18