2017-12-27 23 views
2

Die Ersten Schritte Dokumentation für asyncssh geben Sie das folgende hallo Beispiel:„Asynchron mit“ in Python 3.4

import asyncio, asyncssh, sys 

async def run_client(): 
    async with asyncssh.connect('localhost') as conn: 
     result = await conn.run('echo "Hello!"', check=True) 
     print(result.stdout, end='') 

try: 
    asyncio.get_event_loop().run_until_complete(run_client()) 
except (OSError, asyncssh.Error) as exc: 
    sys.exit('SSH connection failed: ' + str(exc)) 

Dies wird jedoch nicht ausgeführt, weil Asynchron mit nicht in Python unterstützt 3.4:

async with asyncssh.connect('localhost', username='squirtle', password='xxxxxxxxxxxx') as conn: 
    ^
+1

fragen Sie bitte eine andere Frage prüfen, so können wir die Fragen sauber halten – Netwave

+1

ich die Bearbeitung entfernt haben und machte eine neue Frage . – laycat

+0

betrachten https://stackoverflow.com/help/someone-answers – Netwave

Antwort

2

Ich ging und tat es, das funktioniert für mich.

@asyncio.coroutine 
def run_client(): 
     with(yield from asyncssh.connect('localhost', username='root', password='xxxxxxxx')) as conn: 
       result = yield from conn.run('ls', check=True) 
       print(result.stdout, end='')