2016-07-07 11 views
1

ich folgendes Skript im Internet gefunden habe:paramiko Skript mit Fehlern

import paramiko 
    from paramiko import client 


class ssh: 
client = None 

def __init__(self, address, username, password): 
    # Let the user know we're connecting to the server 
    print("Connecting to server.") 
    # Create a new SSH client 
    self.client = client.SSHClient() 
    # The following line is required if you want the script to be able to access a server that's not yet in the known_hosts file 
    self.client.set_missing_host_key_policy(client.AutoAddPolicy()) 
    # Make the connection 
    self.client.connect(address, username=username, password=password, look_for_keys=False) 

def sendCommand(self, command): 
    # Check if connection is made previously 
    if (self.client): 
     stdin, stdout, stderr = self.client.exec_command(command) 
     while not stdout.channel.exit_status_ready(): 
      # Print stdout data when available 
      if stdout.channel.recv_ready(): 
       # Retrieve the first 1024 bytes 
       alldata = stdout.channel.recv(1024) 
       while stdout.channel.recv_ready(): 
        # Retrieve the next 1024 bytes 
        alldata += stdout.channel.recv(1024) 

       # Print as string with utf8 encoding 
       print(str(alldata, "utf8")) 
    else: 
     print("Connection not opened.") 


paramiko.util.log_to_file('paramiko.log') # <----- added line 
connessione = ssh("10.76.80.11","pi","raspberry") 

connessione.sendCommand("arp -a") 

Ich mag würde ein Kommando meine Himbeere mit diesem Skript zu schicken, habe ich versucht, das Programm ohne die Linie zu laufen:

paramiko.util.log_to_file('paramiko.log') 

aber als ich versuchte, den Code auszuführen ich habe diese Laufzeitfehler bekam:

 /usr/bin/python /Users/Marco/PycharmProjects/ssh_control/ssh.py 
    Connecting to server. 
    No handlers could be found for logger "paramiko.transport" 
    Traceback (most recent call last): 
    File "/Users/Marco/PycharmProjects/ssh_control/ssh.py", line 43, in <module> 
    connessione = ssh("10.76.80.11","pi","raspberry") 
    File "/Users/Marco/PycharmProjects/ssh_control/ssh.py", line 16, in __init__ 
    self.client.connect(address, username=username, password=password, look_for_keys=False) 
    File "/Users/Marco/Library/Python/2.7/lib/python/site-packages/paramiko/client.py", line 338, in connect 
     t.start_client() 
    File "/Users/Marco/Library/Python/2.7/lib/python/site- packages/paramiko/transport.py", line 493, in start_client 
    raise e 
    AttributeError: 'EntryPoint' object has no attribute 'resolve' 

     Process finished with exit code 1 

Also suchte ich auf Internet und ich fanden, dass das Problem mit der paramiko.log-Linie behoben werden konnte.

Aber jetzt habe ich einen anderen Fehler:

/usr/bin/python /Users/Marco/PycharmProjects/ssh_control/ssh.py 
    Connecting to server. 
    Traceback (most recent call last): 
    File "/Users/Marco/PycharmProjects/ssh_control/ssh.py", line 38, in <module> 
    connessione = ssh("10.76.80.11","pi","raspberry") 
    File "/Users/Marco/PycharmProjects/ssh_control/ssh.py", line 16, in  __init__ 
    self.client.connect(address, username=username, password=password, look_for_keys=False) 
    File "/Users/Marco/Library/Python/2.7/lib/python/site- packages/paramiko/client.py", line 338, in connect 
    t.start_client() 
    File "/Users/Marco/Library/Python/2.7/lib/python/site-packages/paramiko/transport.py", line 493, in start_client 
raise e 
    AttributeError: 'EntryPoint' object has no attribute 'resolve' 

    Process finished with exit code 1 

Kann jemand hilft mir bitte? weil ich nicht verstehen kann, wo der Fehler ist.

Vielen Dank im Voraus

Antwort

0

Stellt sich heraus, die Sie benötigen Setuptools zu aktualisieren und dann das Paket neu zu installieren. Scheint, dass die ältere Version bei der Installation des Python-Kryptographiepakets etwas kaputt macht.

Versuchen Sie Folgendes ...

pip install -U setuptools 
pin install -U paramiko 

https://github.com/pyca/cryptography/issues/2853

+0

Dank für Sie Specificate wurde hilfe, ich habe das modul neu installiert da es keine fehler gibt, aber das programm immernoch nicht t arbeiten. Wenn ich das Programm mit dem Befehl "reboot" ausführe, passiert nichts, ich denke, es gibt ein Problem im sendCommand() – macco

0

ich mein Problem mit dieser gelöst:

# Make the connection 
    self.client.connect(address, port = 22, username=username, password=password, look_for_keys=False) 

weil der Hafen vor nicht