此问题在此处已有答案:
ICMP pinger application in Python - error: operation not permitted?(1个答案)
昨天关门了。
通过在Python中运行这个简单的代码
>>> from pythonping import ping
>>> ping('127.0.0.1', verbose=True)
我收到此错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/j0tz/.local/lib/python3.10/site-packages/pythonping/__init__.py", line 81, in ping
comm = executor.Communicator(target, provider, timeout, interval, socket_options=options, verbose=verbose, output=out,
File "/home/j0tz/.local/lib/python3.10/site-packages/pythonping/executor.py", line 293, in __init__
self.socket = network.Socket(target, 'icmp', options=socket_options, source=source)
File "/home/j0tz/.local/lib/python3.10/site-packages/pythonping/network.py", line 31, in __init__
self.socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, self.protocol)
File "/usr/lib/python3.10/socket.py", line 232, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted
我试着用sudo运行它,但是没有用。我不知道错误的原因是什么,所以我希望知识渊博的人能给出明智的答案。
Pythonping是我在PyPI上找到的一个公共存储库。在代码中,我尝试简单地ping Localhost,当我将“verbose”参数设置为True时,在屏幕上返回结果。
1条答案
按热度按时间uyto3xhc1#
您需要root用户权限才能使用它
运行python3,比如root用户,那么一切都会好的。如果你在文件上使用它,以root用户运行它。