2

Alright, so i am trying to implement paramiko in my python script.
The aim is to connect to another PC in the same LAN and execute the command through python.

My python version:

Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2

I have a basic code here:

import paramiko
client = paramiko.SSHClient()

host = '192.168.xx.xx'
username = 'username'
password = 'password'

client.connect(host, username=username, password=password)
stdin, stdout, stderr = client.exec_command('ls')
for line in stdout:
    print('... ' + line.strip('\n'))
client.close()

But then I get the following error:

No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last):
  File "testbed.py", line 8, in <module>
    client.connect(host, username=username, password=password)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 385, in connect
    t.start_client(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 543, in start_client
    raise e
TypeError: 'type' object is not iterable
bipster
  • 262
  • 1
  • 4
  • 13

1 Answers1

1

In my case, the error didn't said much

So first I handled No handlers could be found for logger "paramiko.transport" with adding at the top of my script

import logging
logging.getLogger('paramiko.transport').setLevel(logging.DEBUG)
paramiko.util.log_to_file("/tmp/example.log")   <= to redirect the logs to a file

Then I cat /tmp/example.log and found this error https://github.com/pyca/cryptography/issues/4010 (it happens to do with cryptography lib.)

Looking around, I found that there are two libs ( enum and enum34 ) and above

>>> import cryptography
>>> cryptography.__version__
'2.1.3'

you need enum34 vs the default that pip is installing ( enum )

Personally I had another problem, that I first installed enum34 globally vs personal with --user so I did

pip uninstall enum
pip uninstall enum --user
pip install enum34 --user

That worked for me, hope it helps

Ricky Levi
  • 5,482
  • 1
  • 47
  • 55