Python套接字函数错误,找不到socket.gethostbyname

问题描述 投票:1回答:1

我正在编写一个小程序来监视我的网站以及它们是否仍然在线。

我曾在Windows计算机上尝试使用Visual Studio Code进行以下操作,但效果良好:

import socket
hostName = "example.org"
ipAddress = socket.gethostbyname(hostName)
print(ipAddress)

但是我想在Ubuntu系统上运行它,所以我将其转移到了Ubuntu。但是在这里,我总是得到以下编译错误:

Traceback (most recent call last):
File "socket.py", line 1, in <module>
import socket

File "/root/Music/socket.py", line 3, in <module>
ipAddress = socket.gethostbyname(hostName)
AttributeError: module 'socket' has no attribute 'gethostbyname'

我有什么忘了吗?抱歉,我是新来的,所以我会很感谢您的帮助。

我检查了,但是套接字库是最新的:

pip3 install sockets
Requirement already satisfied: sockets in /usr/local/lib/python3.7/dist-packages (1.0.0)

我也卸载并安装了套接字。

python-3.x sockets
1个回答
0
投票

File "/root/Music/socket.py"似乎不是您想要的标准套接字模块,仅出现在模块搜索路径中。您应该从socket.py中删除文件socket.pyc/root/Music

© www.soinside.com 2019 - 2024. All rights reserved.