Paramiko's SSHClient.connect(...) method will raise an exception when packaged with Pyinstaller, but will run fine when not packaged.
This occurs using both of the Pyinstaller flags, --onedir and --onefile. I have tried Pyinstaller versions 3.5 and the current latest dev version, 4.0.dev0+ce887b462. --noupx does not have a noticeable effect.
My Paramiko version is 2.6.0.
My current Python version is 2.7.15
My OS is Windows 10 Pro, Version 10.0.17134, Build 17134.
This issue seems to result from Paramiko calling a C function in kernel32.dll, which unexpectedly returns null only when packaged.
Minimal example:
import paramiko
# The nature of this issue unfortunately requires
# a server that responds to SSH connections to test
host = None # Put a valid hostname here
port = 22 # Put a valid port here
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
hostname=host,
port=port,
username=None,
password=None,
timeout=5
)
I expect the Pyinstaller-packaged version to run exactly the same as the unpackaged version -- in this case, to initiate a SSH connection, then fail with an AuthenticationException, since username and password are None:
> virtualenv venv
> venv\Scripts\activate.bat
> pip install pyinstaller==3.5 paramiko==2.6.0
[output truncated for brevity]
> pyinstaller minimal-paramiko-example.py
[output truncated for brevity]
> dist\minimal-paramiko-example\minimal-paramiko-example.exe
Traceback (most recent call last):
File "minimal-paramiko-example.py", line 16, in <module>
timeout=5
File "site-packages\paramiko\client.py", line 446, in connect
File "site-packages\paramiko\client.py", line 691, in _auth
File "site-packages\paramiko\agent.py", line 379, in __init__
File "site-packages\paramiko\agent.py", line 65, in _connect
File "site-packages\paramiko\agent.py", line 82, in _send_message
File "site-packages\paramiko\win_pageant.py", line 129, in send
File "site-packages\paramiko\win_pageant.py", line 96, in _query_pageant
File "site-packages\paramiko\_winapi.py", line 179, in write
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
[16768] Failed to execute script minimal-paramiko-example
> python minimal-paramiko-example.py # Will result in an AuthenticationException, since username and password are None; this is expected and normal
[output truncated for brevity]
This issue is caused by an interaction with PuTTY Pageant. Closing PuTTY Pageant causes this error to not occur. For some reason, it only manifests in the corner case of:
Using Pyinstaller
Running PuTTY Pageant
Failing to satisfy both requirements will not trigger the issue.
Related
After running "mtt start" i get this error message, what could be the cause of this and how can it be resolved?
/home/me/.local/lib/python3.6/site-packages/google/auth/crypt/_cryptography_rsa.py:22: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
import cryptography.exceptions
INFO|No lab config path set; using standalone mode config
INFO|Using image gcr.io/android-mtt/mtt:prod.
WARNING|No gcloud or service account json key file, can not login to https://gcr.io.
Traceback (most recent call last):
File "/home/me/.local/bin/mtt", line 11, in <module>
load_entry_point('Android-Test-Station-CLI===R30.202206.000', 'console_scripts', 'mtt')()
File "/home/me/.local/lib/python3.6/site-packages/multitest_transport/cli/cli.py", line 1204, in Main
args.func(args)
File "/home/me/.local/lib/python3.6/site-packages/multitest_transport/cli/cli.py", line 367, in Start
_StartMttNode(args, host)
File "/home/me/.local/lib/python3.6/site-packages/multitest_transport/cli/cli.py", line 399, in _StartMttNode
if docker_helper.IsContainerRunning(args.name):
File "/home/me/.local/lib/python3.6/site-packages/multitest_transport/cli/command_util.py", line 974, in IsContainerRunning
container_name, res.stderr, res.stdout))
multitest_transport.cli.command_util.DockerError: Failed to inpect mtt:
stderr:Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/mtt/json": dial unix /var/run/docker.sock: connect: permission denied
stdout:
.
I have to maintain an old website built using Python2.7 that needs to continue working until we've finished creating a completely new version with more modern tools. Now this old website needs access to a remote MySQL database (connection is set up and working correctly), which so far has worked using the following:
import MySQLdb
db = MySQLdb.connect(host=Host,user=User,passwd=Pass,db=DBse)
Now the server has been upgraded from Ubuntu 18.04. to Ubuntu 20.04., and while I managed to install pip and MySQLdb for Python2.7, I now get the following error for the lines above:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2026, 'SSL connection error: unknown error number')
The SSL connection works fine in Python3 or directly from the command line.
Is there anything I can do to make this work?
Locate and add the line skip_ssl in /etc/mysql/my.cnf ( have tried this on MySQL 8.0.29 , Ubuntu 18)
This was the only thing that worked for me.
[mysqld]
skip_ssl
I have 2 servers. I am attempting to setup one for continuous integration for my main website server
Web server 1(cloud-hosting):
Python3.6
Django3.1
Ubuntu16.04
Webserver 2(VPS):
Python3.7
Django3.1
Ubuntu16.04
Jenkins
--ShiningPanda(plugin)
Im new to web development, so if it seems odd as far as my web server types, that is why. I have been following along in the book Test Driven Development with Python. My issue is that when running python manage.py test [app] My [app] inherits from the class StaticLiveSever to generate a testing environment. On webserver 1, this works fine. On webserver 2, i get an error that the request address cannot be assigned. I use jenkins to build the environment, but the error i get is OSerror[99]:cannot assign requested address. I dont understand why this is happening when i run the same commands in Web Sever 1. It runs fine. Although again, the commands are run by jenkins and jenkins is configured to run python3.7
Full Traceback(Main Issue)
Traceback (most recent call last):
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/django/test/testcases.py", line 1449, in setUpClass
raise cls.server_thread.error
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/django/test/testcases.py", line 1374, in run
self.httpd = self._create_server()
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/django/test/testcases.py", line 1389, in _create_server
return ThreadedWSGIServer((self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False)
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 67, in __init__
super().__init__(*args, **kwargs)
File "/usr/lib/python3.7/socketserver.py", line 452, in __init__
self.server_bind()
File "/usr/lib/python3.7/wsgiref/simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "/usr/lib/python3.7/http/server.py", line 137, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/lib/python3.7/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 99] Cannot assign requested address
After hardcoded host
Traceback (most recent call last):
File "/var/lib/jenkins/workspace/Superlists/functional_tests/base.py", line 47, in setUp
self.browser = webdriver.Firefox()
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 100, in start
self.assert_process_still_running()
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 113, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 69
geckodriver.log w/ hardcoded host ip in LiveTestServer
eckodriver: error: Address not available (os error 99)
geckodriver 0.27.0 (7b8c4f32cdde 2020-07-28 18:16 +0000)
WebDriver implementation for Firefox
USAGE:
geckodriver [FLAGS] [OPTIONS]
[...]
Hopefully the tracebacks above are not too confusing. Ultmiately what i did notice was the when im in webserver 2, i access the Django testcases.py module that has LiverServerThread and hardcode host=0.0.0.0 instead of host=localhost (1st traceback). The connection is then made although then the problem lies with geckodriver and the same thing (2nd traceback). I need to hard code ip 0.0.0.0 to be able to establish a connection, but then geckodriver is just listening, which i am assuming, at a completely different location (no error.log shown here).
So 1st id like to at least be able to make a connection to run the LiveServerThread class properly. Then try and resolve the issue with geckodriver. I also was not sure if the type of servers im running on poses as the problem.
I am trying to connect to a SSH server using the python library paramiko.
The same code worked on the same computer before, but it started to show a warning when trying to connect. I can connect to the SSH server using the same computer and same users via terminal. The python code also works on other computers connected to the same LAN network.
I also tried to restart both pcs and reinstall paramiko with no success.
Following is the code and the warning message presented.
class SSH:
def __init__(self, ip):
self.ssh = SSHClient()
self.ssh.load_system_host_keys()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(hostname=ip ,username='urs',password='pass')
Warning message:
Unknown exception: '_EllipticCurvePublicKey' object has no attribute 'verify'
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 1886, in run
self.kex_engine.parse_next(ptype, m)
File "/usr/local/lib/python3.5/dist-packages/paramiko/kex_ecdh_nist.py", line 47, in parse_next
return self._parse_kexecdh_reply(m)
File "/usr/local/lib/python3.5/dist-packages/paramiko/kex_ecdh_nist.py", line 105, in _parse_kexecdh_reply
self.transport._verify_key(K_S, sig)
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 1748, in _verify_key
if not key.verify_ssh_sig(self.H, Message(sig)):
File "/usr/local/lib/python3.5/dist-packages/paramiko/ecdsakey.py", line 216, in verify_ssh_sig
self.verifying_key.verify(
AttributeError: '_EllipticCurvePublicKey' object has no attribute 'verify'
Do anybody have a suggestion about where the problem might be?
I tried to google and looked for the error here,but couldn't find it anywhere.
Thanks in advance!
I had the exact same error as now. I encountered this error with paramiko version 2.3.0. I downgraded to 2.1.2 and the operation i was doing proceeded normally.
I am using openssh in iron python to run commands from windows to linux. I have installed openssh in both the machines and the service is running. I have added keys in authorized users even
conn = SSHConnection(ip_addr, login=name)
ret = conn.run('ls')
or
ret = conn.run(['ls'])
I am getting error as follows
"C:\Program Files\IronPython 2.7\lib\site-packages\openssh_wrapper.py", line 164, in run
"C:\Program Files\IronPython 2.7\Lib\subprocess.py", line 675, in __init__
"C:\Program Files\IronPython 2.7\Lib\subprocess.py", line 887, in _execute_child
Error: [Errno 2] The system cannot find the file specified.
What is wrong in the code?
The line in my copy is
ssh_command = self.ssh_command(interpreter, forward_ssh_agent)
where interpreter, if not specified, defaults to /bin/bash. I think it's saying it doesn't see /bin/bash on the remote machine.