Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL wrap socket: AttributeError: 'module' object has no attribute 'wrap_socket'

Tags:

python

ssl

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?

like image 348
FLX Avatar asked Oct 19 '25 05:10

FLX


1 Answers

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 .

like image 117
mouad Avatar answered Oct 21 '25 18:10

mouad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!