名称或服务未知 [英] Name or service not known

查看:124
本文介绍了名称或服务未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用以下代码获取登录计算机的用户的ipaddress,但出现错误。

I have been trying to get the ipaddress of the person who logged into the machine using the below code but I get a error.

>>> import socket
>>> socket.gethostbyname_ex(socket.gethostname())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known

相同的代码在其他Linux盒中工作。
不知道我要解决此问题。

The same code works in other linux box. Not sure I fix it.

推荐答案

由于未正确设置主机名而发生了错误。在三个不同的位置设置主机名-

Error has occurred just because of not setting up hostname properly. Set the hostname at three different places, which are in -



  1. / etc / hostname

  2. / etc / hosts

  3. 运行命令$ hostname


然后注销并再次登录。完成了。

then logout and login again. You are done.

这篇关于名称或服务未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆