user6202827 user6202827 - 2 months ago 31
Python Question

paramiko.transport throws runtime ValueError while connecting to remote server using ssh

I'm a beginner in Python and trying to build an application for my project to fetch logs from a remote server using 'Python 2.7.11'. I use 'Paramiko 2.0.0' and 'cryptography 1.3.2' to achieve this task. The script works fine when executed directly from IDLE. Then I used latest PyInstaller - 3.2 for creating an executable of this application. But the executable throws run-time error while creating a ssh connection with the server.

When this exe file is executed, while trying to connect to server with the code:

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname='<ip address is hardcoded here>',port=22, username='root', password='<password is hardcoded here>')


The last line throws runtime error:
Multibackend cannot be initialized with no backends. If you are seeing this error when trying to use default_backend() please try uninstalling and reinstalling cryptography."

As mentioned in the error message, I tried uninstalling and reinstalling cryptograpy, but this did not work.
I have used '
paramiko. util. log_to_file ('C:\Python27\paramiko.log')
' to collect the loggings during runtime and it shows the below results:

DEB [20160510-11:28:40.530] thr=1 paramiko.transport: starting thread (client mode): 0x2b74890L
DEB [20160510-11:28:40.530] thr=1 paramiko.transport: Local version/idstring: SSH-2.0-paramiko_2.0.0
DEB [20160510-11:28:40.536] thr=1 paramiko.transport: Remote version/idstring: SSH-2.0-OpenSSH_4.3
INF [20160510-11:28:40.536] thr=1 paramiko.transport: Connected (version 2.0, client OpenSSH_4.3)
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: kex algos:[u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] client mac:[u'hmac-md5', u'hmac-sha1', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] server mac:[u'hmac-md5', u'hmac-sha1', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] client compress:[u'none', u'zlib@openssh.com'] server compress:[u'none', u'zlib@openssh.com'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Kex agreed: diffie-hellman-group1-sha1
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Cipher agreed: aes128-ctr
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: MAC agreed: hmac-md5
DEB [20160510-11:28:40.539] thr=1 paramiko.transport: Compression agreed: none
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: Unknown exception: Multibackend cannot be initialized with no backends. If you are seeing this error when trying to use default_backend() please try uninstalling and reinstalling cryptography.
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: Traceback (most recent call last):
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\transport.py", line 1757, in run
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\kex_group1.py", line 75, in parse_next
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\kex_group1.py", line 111, in _parse_kexdh_reply
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\transport.py", line 1602, in _verify_key
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\paramiko\rsakey.py", line 58, in __init__
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\cryptography\hazmat\backends\__init__.py", line 35, in default_backend
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: File "site-packages\cryptography\hazmat\backends\multibackend.py", line 33, in __init__
ERR [20160510-11:28:40.582] thr=1 paramiko.transport: ValueError: Multibackend cannot be initialized with no backends. If you are seeing this error when trying to use default_backend() please try uninstalling and reinstalling cryptography.


Kindly help me to understand and debug this problem, as I'm new on Python and not much familiar with debugging python codes in depth.
Also please let me know if any more information regarding the script is required for analysis.

Answer

I had the same issue, using PyInstaller - 2.1, other versions same as you.

Downgrading paramiko to version 1.17 and rebuilding the exe with PyInstaller solved the issue for me,

pip uninstall paramiko
pip install paramiko==1.17
Comments