2016-06-01 2 views
0

Vor allem Entschuldigung für mein schlechtes Englisch.Fehler beim Kompilieren unter Windows ein einfaches Python-Skript (mit py2exe)

Ich machte ein Skript, das eine Verbindung zu einem Mikotik RB750 herstellt und Befehle per SSH ausführt. Wenn ich es (ohne Kompilierung) läuft, funktioniert es gut und erfüllt das Ziel. Das Problem, das ich habe, ist, dass, wenn ich versuche, es unter Windows zu kompilieren fehlschlägt. Funktioniert gut, bis es versucht, die SSH-Verbindung auszuführen.

Ich versuche, es mit dem Befehl python -m py2exe.build_exe ssh_menu.py zu kompilieren Es sagt mir, dass 4 Module fehlen: UserDict; gssapi; Verpackung; Zeile lesen. Ich habe keine Ahnung, wie ich das lösen kann, und ich google viel, bemitleidenswert ist dies das erste Mal, dass ich versuche, etwas mit Python zu tun, und ich bin jetzt verloren.

Hier ist mein Code:

import os 
import sys 
import time 
import select 
import paramiko 
server, username, password = ('192.168.88.1', 'admin', '976431') 
comando1=" " 
comando2=" " 
ipUbicacion=" " 
flagUbicacion=True 
ipSalida=" " 
flagSalida=True 
addresList1=" " 
miIp=input("Cual es su dirección IP: ") 
while flagUbicacion: 
    print(""" 
     1.ESSO Centro 
     2.ESSO Rotonda 
     3.Casa Don Oscar/Sebastian 
     4.Transporte Garay 
     5.Salir 
    """) 
idUbicacion=input("Cual es su ubicación? ") 
if idUbicacion=="1": 
    ipUbicacion="192.168.88.1" 
    flagUbicacion=False 
elif idUbicacion=="2": 
    ipUbicacion="192.168.88.2" 
    flagUbicacion=False 
elif idUbicacion=="3": 
    ipUbicacion="192.168.88.3" 
    flagUbicacion=False 
elif idUbicacion=="4": 
    ipUbicacion="192.168.88.4" 
    flagUbicacion=False 
elif idUbicacion=="5": 
    print("\n Programa Terminado") 
    idUbicacionans = None 
else: 
    print("\n El dato ingresado no es valido") 
while flagSalida: 
    print(""" 
    1.Modem ESSO Centro 
    2.Integra ESSO Centro 
    3.Modem ESSO Rotonda 
    4.Modem Casa Don Oscar 
    5.10+ Transporte Garay 
    6.GampelCom Transporte Garay 
    7.Salir 
    """) 
idSalida=input("Por cual puerta de enlace quiere salir? ") 
if idSalida=="1": 
    ipSalida="192.168.88.1" 
    auxUbicacion="1" 
    flagSalida=False 
elif idSalida=="2": 
    ipSalida="192.168.88.1" 
    auxUbicacion="1" 
    flagSalida=False 
elif idSalida=="3": 
    ipSalida="192.168.88.2" 
    auxUbicacion="2" 
    flagSalida=False 
elif idSalida=="4": 
    ipSalida="192.168.88.3" 
    auxUbicacion="3" 
    flagSalida=False 
elif idSalida=="5": 
    ipSalida="192.168.88.4" 
    auxUbicacion="4" 
    flagSalida=False 
elif idSalida=="6": 
    ipSalida="192.168.88.4" 
    auxUbicacion="4" 
    flagSalida=False 
elif idSalida=="7": 
    print("\n Programa Terminado") 
    idSalida = None 
    flagSalida=False 
else: 
    print("\n El dato ingresado no es valido") 
if ipUbicacion==ipSalida: 
    cantComandos=1 
else: 
    cantComandos=2 
i=0 
while i<cantComandos: 
    if idUbicacion=="1": #SI ESTOY EN LA ESSO DEL CENTRO Y... 
     if idSalida=="1": #...QUIERO SALIR POR EL MODEM 
      addresList1="WAN1" 
     elif idSalida=="2": #...QUIERO SALIR POR EL INTEGRA 
      addresList1="WAN2" 
     elif idSalida=="3": #...QUIERO SALIR POR RB_ROTONDA 
      addresList1="WAN3" 
     elif idSalida=="4": #...QUIERO SALIR POR RB_OSCAR 
      addresList1="WAN4" 
     elif idSalida=="5": #...QUIERO SALIR POR RB_TRANSPORTE 
      addresList1="WAN5" 
     elif idSalida=="6": #...QUIERO SALIR POR RB_TRANSPORTE 
      addresList1="WAN5" 
    if idUbicacion=="2": #SI ESTOY EN LA ESSO DE LA ROTONDA Y... 
     if idSalida=="1": #...QUIERO SALIR POR RB_CENTRO 
      addresList1="WAN2" 
     elif idSalida=="2": #...QUIERO SALIR POR RB_CENTRO 
      addresList1="WAN2" 
     elif idSalida=="3": #...QUIERO SALIR POR MODEM ROTONDA 
      addresList1="WAN1" 
     elif idSalida=="4": #...QUIERO SALIR POR RB_OSCAR 
      addresList1="WAN3" 
     elif idSalida=="5": #...QUIERO SALIR POR RB_TRANSPORTE 
      addresList1="WAN4" 
     elif idSalida=="6": #...QUIERO SALIR POR RB_TRANSPORTE 
      addresList1="WAN4" 
    if idUbicacion=="3": #SI ESTOY EN LA CASA DE OSCAR Y... 
     if idSalida=="1": #...QUIERO SALIR POR RB_CENTRO 
      addresList1="WAN2" 
     elif idSalida=="2": #...QUIERO SALIR POR RB_CENTRO 
      addresList1="WAN2" 
     elif idSalida=="3": #...QUIERO SALIR POR RB_ROTONDA 
      addresList1="WAN3" 
     elif idSalida=="4": #...QUIERO SALIR POR MODEM OSCAR 
      addresList1="WAN1" 
     elif idSalida=="5": #...QUIERO SALIR POR RB_TRANSPORTE 
      addresList1="WAN4" 
     elif idSalida=="6": #...QUIERO SALIR POR RB_TRANSPORTE 
      addresList1="WAN4" 
    if idUbicacion=="4": #SI ESTOY EN TRANSPORTE Y... 
     if idSalida=="1": #...QUIERO SALIR POR RB_CENTRO 
      addresList1="WAN3" 
     elif idSalida=="2": #...QUIERO SALIR POR RB_CENTRO 
      addresList1="WAN3" 
     elif idSalida=="3": #...QUIERO SALIR POR RB_ROTONDA 
      addresList1="WAN4" 
     elif idSalida=="4": #...QUIERO SALIR POR RB_OSCAR 
      addresList1="WAN5" 
     elif idSalida=="5": #...QUIERO SALIR POR 10+ TRANSPORTE 
      addresList1="WAN1" 
     elif idSalida=="6": #...QUIERO SALIR POR GAMPELCOM TRANSPORTE 
      addresList1="WAN2" 
    if i==0: 
     server=ipUbicacion 
     while True: 
      print ("Conectando a "+server+": Intento "+repr(i)+" de 10") 
      try: 
       ssh = paramiko.SSHClient() 
       ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
       ssh.connect(server, username=username, password=password) 
       print ("Conectado a "+server) 
      break 
      except paramiko.AuthenticationException: 
       print ("Fallo de autentificación conectando a "+server) 
      except: 
       print ("Fallo de SSH en "+server+", esperando que se inicie") 
      i += 1 
      time.sleep(1) 
     if i == 10: 
      print ("No se pudo conectar a "+server+". Conexión cancelada") % server 
    ssh.exec_command('ip firewall address-list remove [find where address="'+miIp+'"]') 
    ssh.exec_command('ip firewall address-list add list="'+addresList1+'" address="'+miIp+'"') 
    print('ip firewall address-list add list="'+addresList1+'" address="'+miIp+'"') 
    print ("Comando ejecutado, cerrando conexión SSH") 
    ssh.close() 
    time.sleep(1) 
else: 
    server=ipSalida 
    while True: 
     print ("Conectando a "+server+": Intento "+repr(i)+" de 10") 
     try: 
      ssh = paramiko.SSHClient() 
      ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
      ssh.connect(server, username=username, password=password) 
      print ("Conectado a "+server) 
      break 
     except paramiko.AuthenticationException: 
      print ("Fallo de autentificación conectando a "+server) 
     except: 
      print ("Fallo de SSH en "+server+", esperando que se inicie") 
      i += 1 
      time.sleep(1) 
     if i == 10: 
      print ("No se pudo conectar a "+server+". Conexión cancelada") % server 
    ssh.exec_command('ip firewall address-list remove [find where address="'+miIp+'"]') 
    ssh.exec_command('ip firewall address-list add list="'+addresList1+'" address="'+miIp+'"') 
    print('ip firewall address-list add list="'+addresList1+'" address="'+miIp+'"') 
    print ("Comando ejecutado, cerrando conexión SSH") 
    ssh.close() 
    time.sleep(1) 
idUbicacion=auxUbicacion 
i=i+1 

Antwort

0

Wenn ein Python-Programm kompiliert, neige ich dazu, statt py2exe cxfreeze zu verwenden (verwenden Sie den Befehl pip install CX_Freeze aus der Windows-Eingabeaufforderung), wo Sie diesen Code verwenden können, um zu kompilieren das Programm:

cxfreeze "Path\To\File.py" --target-dir "Path\to\exe\file\"

Path\To\File.py ist der Verzeichnisbaum auf der python-Datei, die Sie

zu kompilieren versuchen

Path\to\exe\file\ ist der Verzeichnisbaum auf einen Ordner, in dem das kompilierte Programm wird gespeichert (ich empfehle diese leer zu sein)

Weitere Details finden here.

Hoffe, das hilft.

+0

Vielen Dank für die Antwort, aber ich habe immer noch den gleichen Fehler [Screenshot] ( –

+0

) Ich habe darüber nachgedacht, und das einzige, was ich vorschlagen kann Neuinstallation von 'crytography', wie die Fehlermeldung suggeriert, wäre die beste Option, dies zu tun, auf eine neuere Version von Python zu aktualisieren (es kann immer noch die gleiche Version sein, wie 3.4, nur mit dem neuesten Update) oder manuell installieren versuchen es ('pip Install --upgrade kryptography'), die möglicherweise nicht funktioniert – sonrad10

+0

Ich bemerke, dass Sie zwei Zeilen von' print ("Conectando a" + Server + ": Intento" + repr (i) + "de 10" 'Könnten Sie bitte erarbeiten Sie, welche Zeile auf der Fehlermeldung angezeigt wird, die Sie gesendet haben, es könnte helfen, den Fehler zu lokalisieren und das Problem zu beheben – sonrad10

Verwandte Themen