为什么在使用 Fabric python 库时会收到低级套接字错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1469431/
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
Why am I receiving a low level socket error when using the Fabric python library?
提问by Matthew Rankin
When I run the command:
当我运行命令时:
fab -H localhost host_type
I receive the following error:
我收到以下错误:
[localhost] Executing task 'host_type'
[localhost] run: uname -s
Fatal error: Low level socket error connecting to host localhost: Connection refused
Aborting.
Any thoughts as to why? Thanks.
关于为什么的任何想法?谢谢。
Fabfile.py
Fabfile.py
from fabric.api import run
def host_type():
run('uname -s')
Configuration
配置
- Fabric 1.0a0 (installed from the most recent Github commit---b8e1b6a)
- Paramiko 1.7.4
- PyCrypto 2.0.1
- Virtualenv ver 1.3.3
- Python 2.6.2+ (release26-maint:74924, Sep 18 2009, 16:03:18)
- Mac OS X 10.6.1
- Fabric 1.0a0(从最近的 Github 提交安装---b8e1b6a)
- 帕拉米科 1.7.4
- PyCrypto 2.0.1
- Virtualenv 1.3.3 版
- Python 2.6.2+ (release26-maint:74924, Sep 18 2009, 16:03:18)
- Mac OS X 10.6.1
回答by Mark Rushakoff
The important part isn't the "low level error" part of the message - the important part is the "Connection refused" part. You'll get a "connection refused" message when trying to connect to a closed port.
重要的部分不是消息的“低级错误”部分——重要的部分是“连接被拒绝”部分。尝试连接到关闭的端口时,您会收到“连接被拒绝”消息。
The most likely scenario is that you are not running an ssh server on your machine at the time that Fabric is running. If you do
最可能的情况是在 Fabric 运行时您的机器上没有运行 ssh 服务器。如果你这样做
ssh localhost
you'll probably get a message similar to
您可能会收到类似于以下内容的消息
ssh: connect to host localhost: Connection refused
So you'll have to go out and set up an SSH server on your computer before you can proceed with Fabric from there.
所以你必须出去在你的计算机上设置一个 SSH 服务器,然后才能从那里继续使用 Fabric。
回答by RichVel
This can also happen in OS X 10.11.4 and Fabric 1.10.1, in the case where you are ssh'ing to a VM using Vagrant, which does port forwarding from localhost. In this case, localhost was resolving to the IPv6 ::1
address (not due to /etc/hosts
file), and giving this error.
这也可能发生在 OS X 10.11.4 和 Fabric 1.10.1 中,如果您使用 Vagrant ssh 连接到虚拟机,它会从本地主机进行端口转发。在这种情况下,本地主机解析到 IPv6::1
地址(不是由于/etc/hosts
文件),并给出此错误。
The fix was to force use of IPv4 by using the 127.0.0.1
address in the fabfile instead of the hostname. Using a hostname in /etc/hosts
with this address didn't work.
修复是通过使用127.0.0.1
fabfile 中的地址而不是主机名来强制使用 IPv4 。在/etc/hosts
此地址中使用主机名不起作用。
You might also want to try these useful tips for debugging connection issues in Fabric.
您可能还想尝试这些有用的技巧来调试 Fabric 中的连接问题。
回答by Hraban
I had the same problem, but the reason was different: While I could easily log in to the server via SSH (default port 22), fabric tried to connect on a closed port 9090.
我遇到了同样的问题,但原因不同:虽然我可以通过 SSH(默认端口 22)轻松登录到服务器,但fabric 尝试在关闭的端口 9090 上进行连接。
Finally I recognized that I had defined "env.port=9090" in my old fabfile for some WSGI server setup; while that was never a problem, I updated my Python installation some weeks before, and fabric now uses env.port for its SSH connection. I just renamed that config, and all is well again.
最后我意识到我已经在我的旧 fabfile 中为一些 WSGI 服务器设置定义了“env.port=9090”;虽然这从来都不是问题,但几周前我更新了我的 Python 安装,结构现在使用 env.port 进行 SSH 连接。我刚刚重命名了那个配置,一切又好了。
回答by weiwang
env.roledefs = {
'role1': env.hosts[0:5],
'role2':[env.hosts[5],]
}
I encountered the same error if "role" value IS NOT A LIST. for example, the above code works but the following doesn't.
如果“角色”值不是列表,我遇到了同样的错误。例如,上面的代码有效,但下面的无效。
env.roledefs = {
'role1': env.hosts[0:5],
'role2':env.hosts[5],
}