简单套接字调用返回socket.gaierror:[Errno 8]

时间:2015-09-17 13:30:23

标签: python django python-3.x error-handling

我有这个非常简单的代码:

print(socket.gethostbyname(socket.gethostname()))

那应该是我的IP地址。

但是它返回了一个错误:

socket.gaierror: [Errno 8] nodename nor servname provided, or not known

有什么想法吗?

一些细节:

socket.gethostname()

返回:

'airdevincent2'

1 个答案:

答案 0 :(得分:0)

找到答案!!!

我在MacOs上,而/ etc / hosts文件中没有提及“airdevincent2”主机。

所以我添加了这一行:

127.0.0.1   airdevincent2

Etvoilà!