简体   繁体   中英

Why am I receiving a low level socket error when using the Fabric python library?

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

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

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

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.

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.

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.

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.

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.

You might also want to try these useful tips for debugging connection issues in Fabric .

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],
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM