问题
so I've writing this code where I connect to a computer over SSH using Paramiko, the script works normally, but when I convert it to ".exe" using cx_Freeze the program stops working at "self.ssh.load_system_host_keys", so i remove that function from the script and it kept working as usual (maybe not always needed?), but then again, when I converted the script to .exe, it was the "self.ssh.connect" function of Paramiko which now seems to be stopping the program, and by that i mean, no exception raises, the code just stops running right there and nothing happens, any thoughts?.
Are there any compatibility issues with Paramiko and cx_Freeze?
Here's a simplified version of my code:
session.py (Class in which I implemented the paramiko functionality)
from paramiko import SSHClient, AutoAddPolicy
class Session:
def __init__(self, host, user, password):
self.user = user
self.password = password
self.host = host
self.is_connected = False
self.ssh = SSHClient()
self.ssh.set_missing_host_key_policy(AutoAddPolicy())
def assert_connection(self):
# force connection
time_start = time.time()
while True:
try:
self.ssh.connect(self.host, username=self.user, password=self.password)
self.is_connected = True
return True
except:
print(time.time() - time_start)
if (time.time() - time_start) > 3:
self.ssh.close()
return False
The "Main" Script
import session
import threading
def create_session(self):
self.session = session.Session(self, self.active_session.host,
self.active_session.user, self.active_session.password)
t = threading.Thread(target=self.connect_via_ssh)
t.start()
def connect_via_ssh(self):
if self.session.assert_connection():
#Do something
Any help would be much appreciated!
Edit:
I wasn't able to figure out what was going wrong, however i tryed using pyinstaller, and it did work! i bet there's some wierd bug with cx_freeze and paramiko.
来源:https://stackoverflow.com/questions/49660621/paramiko-not-working-properly-after-cx-freeze