gaierror: [Errno 8] nodename nor servname provided, or not known (with macOS Sierra)

匿名 (未验证) 提交于 2019-12-03 02:45:02

问题:

socket.gethostbyname(socket.gethostname()) worked well on OS X El Capitan. However, it's not working now after the Mac updated to macOS Sierra.

Thanks!

import socket socket.gethostbyname(socket.gethostname())  Traceback (most recent call last):   File "<pyshell#26>", line 1, in <module>     socket.gethostbyname(socket.gethostname()) gaierror: [Errno 8] nodename nor servname provided, or not known 

回答1:

There is an answer in OP's comments based on another question, which requires to edit /etc/hosts, i.e echo 127.0.0.1 $HOSTNAME >> /etc/hosts.

Alternatively, you can use socket.gethostbyname('localhost'), assuming that localhost is what you need and it is defined in your /etc/hosts.



回答2:

Same problem tome. I change the code to:

import socket socket.gethostbyname("") 

And it works now.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!