2

The Getting Started docs for asyncssh give the following hello example:

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))

However, this will not run, because async with is not supported in Python 3.4:

async with asyncssh.connect('localhost', username='squirtle', password='xxxxxxxxxxxx') as conn:
     ^
3
  • 1
    please ask another question with your edit, so we can keep the questions clean Commented Dec 27, 2017 at 8:40
  • 1
    I've removed the edit and made a new question. Commented Dec 27, 2017 at 9:08
  • consider stackoverflow.com/help/someone-answers Commented Dec 27, 2017 at 18:39

2 Answers 2

2

I went and did it, this works for me.

@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='')
Sign up to request clarification or add additional context in comments.

Comments

2

async keyword was introduced in Python 3.5, you should use asyncio.corutine in earlier versions.

Check PEP492 and Python 3.5 release notes

Also you would like to check this SO Question and answers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.