这是我正在尝试运行的代码:
from pexpect import pxssh
s = pxssh.pxssh()
if not s.login ('myip', 'myusername', 'mypassword'):
print ("SSH session failed on login.")
print (str(s))
else:
print ("SSH session login successful")
s.sendline ('ls -l')
s.prompt() # match the prompt
print (s.before) # print everything before the prompt.
s.logout()
我运行时遇到的错误是:
Traceback (most recent call last):
File "test_pexpect.py", line 1, in <module>
from pexpect import pxssh
File "C:\Python35\lib\site-packages\pexpect\pxssh.py", line 23, in <module>
from pexpect import ExceptionPexpect, TIMEOUT, EOF, spawn
ImportError: cannot import name 'spawn'
有人能帮我吗?我在 Windows 上使用 Python 3.5
from pexpect import pxssh
也给了我同样的问题。我也找不到其他使用pxssh的替代方法,所以要么当前版本的pip中有一个bug,要么就有另一种使用它的方式,但我在pexpect/pssh文档的快速浏览中没有找到。我没有时间进一步调查,但想分享一下我的经验! - Anna