Python “gaierror: [Errno -3] 名称解析暂时失败”是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40238610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:20:07  来源:igfitidea点击:

What is the meaning of "gaierror: [Errno -3] Temporary failure in name resolution"

pythonsockets

提问by Kurt Peek

I'm trying to run a Flask app which ends in an error. If I trace back what is happening, I can reproduce the problem with the following iPython commands:

我正在尝试运行以错误结尾的 Flask 应用程序。如果我追溯正在发生的事情,我可以使用以下 iPython 命令重现该问题:

In [14]: import socket

In [15]: s = socket.socket()

In [16]: s.connect(('rabbitmq', 5672))
---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
<ipython-input-16-71a261d976b3> in <module>()
----> 1 s.connect(('rabbitmq', 5672))

/usr/lib/python2.7/socket.pyc in meth(name, self, *args)
    226 
    227 def meth(name,self,*args):
--> 228     return getattr(self._sock,name)(*args)
    229 
    230 for _m in _socketmethods:

gaierror: [Errno -3] Temporary failure in name resolution

I was unable to find much documentation on the underlying reasons for "Temporary failure in name resolution". One possible reason for the problem is that I'm trying to run the app locally whereas it is usually initialized in a docker-compose environment. Any ideas what is causing this error?

我找不到关于“名称解析暂时失败”的根本原因的大量文档。问题的一个可能原因是我试图在本地运行应用程序,而它通常是在 docker-compose 环境中初始化的。任何想法是什么导致此错误?

回答by ElmoVanKielmo

gaierror= Get Address Info Error

gaierror= g ^ddressNFO错误

Temporary failure in name resolution= No known DNS was able to answer with the IP address of rabbitmqdomain.

名称解析暂时失败= 没有已知的 DNS 能够使用rabbitmq域的 IP 地址进行应答

I guess you don't expect this to be a real domain name. Put the entry for rabbitmqhost in /etc/hosts.

我猜你不希望这是一个真正的域名。将rabbitmq主机条目放入/etc/hosts.

Alternatively change:

或者改变:

s.connect(('rabbitmq', 5672))

into:

进入:

s.connect(('IP.OF.RABBITMQ.SERVER', 5672))

Of course I mean real IP and not the dummy string I put there for explanation.

当然,我的意思是真正的 IP,而不是我放在那里用于解释的虚拟字符串。