代码运行良好,现在显示错误
AttributeError: 模块“socket”没有属性“AF_INET”
代码如下: 模块名称不是 socket.py
import socket
client= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host='192.168.xx.x'
port=4196
client.connect((host, port))
print("connected to IP", host,"and port", port)
Run Code Online (Sandbox Code Playgroud)
错误:
`Traceback (most recent call last):
File "C:\Users\User\eclipse-workspace\New\soc.py", line 1, in <module>
import socket
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 2, in <module>
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
AttributeError: module 'socket' has no attribute 'AF_INET'
Run Code Online (Sandbox Code Playgroud)
`
您的项目目录中可能有一个命名的模块socket.py,在这种情况下,当您执行import socket. 将项目目录中的重命名socket.py为其他名称,您的代码就可以工作了。