gpt4 book ai didi

python - SSL 包装套接字 : AttributeError: 'module' object has no attribute 'wrap_socket'

转载 作者:太空宇宙 更新时间:2023-11-04 06:44:59 39 4
gpt4 key购买 nike

我正在使用 python 2.6 在 OSX 上创建一个非常简单的示例,但我不断得到:

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'

代码:

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()

我做错了什么?

谢谢!

丹尼斯

最佳答案

不要将脚本命名为 ssl.py,因为当您将脚本命名为 ssl.py 并执行 import ssl 时,您重新导入相同的脚本。

关于python - SSL 包装套接字 : AttributeError: 'module' object has no attribute 'wrap_socket' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4818280/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com