Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python3 fabric import Error: cannot import Connection

Tags:

python-3.x

import os
import string
from fabric import Connection
import configparser
import socket


config = configparser.RawConfigParser(allow_no_value=True)
configFilePath = r'/root/config.ini'
config.read(configFilePath)
puser = config.get('Server', 'user')
#print (puser)
db_server = list(config.items('Database'))
#print (db_server)


def host_connect():
    for key in db_server:
        print (key[0])
        conn = Connection(host="puser@{0}".format(key[0]))
        conn.run('ps -ef | grep postgres')

I am trying to run this code and getting error as Traceback (most recent call last): File "psql_cleanlogs.py", line 6, in from fabric import Connection ImportError: cannot import name 'Connection'

The same procedure I have done in different codes and it ran fine but here is it is creating troubles. I am using python3 virtual env

like image 757
Roxy Avatar asked Aug 07 '18 21:08

Roxy


Video Answer


1 Answers

I was facing a similar issue, I checked the downloaded fabric package contents, it didn't have Connection.py (maybe the wrong repo from where I downloaded the package). I installed fabric2 from the correct repository (https://pypi.python.org/simple) and it worked.

from fabric2 import Connection
like image 91
avp Avatar answered Oct 17 '22 20:10

avp