执行socket.gethostbyname(socket.gethostname()) 报 socket.gaierror: [Errno -2] Name or service not known 错误。分析记录如下:
更正前
执行命令vi /etc/hosts:

执行命令:vi /etc/hostname:

更正后
执行命令vi /etc/hosts:

执行命令:vi /etc/hostname:

验证

总结
这个错误是由 /etc/hostname里的hostname 和 /etc/hosts里的 IP hostname 值不一致造成的
参考链接:
https://www.cnblogs.com/123rongzhi/p/16140849.html

当执行socket.gethostbyname(socket.gethostname())时遇到socket.gaierror: [Errno-2] Name or service not known错误,问题根源在于/etc/hostname中的hostname与/etc/hosts中的IPhostname不匹配。修复方法包括检查并确保这两个文件中的信息一致。参考链接提供了详细的解决方案。
1万+

被折叠的 条评论
为什么被折叠?



