问题描述
由于pexpect pxssh
在Windows中无法使用,
https://stackoverflow.com/a/43739177/13353532
>>> from pexpect import pxssh
Traceback (most recent call last):
File "<stdin>",line 1,in <module>
File "C:\Users\wolf\AppData\Local\Programs\Python\Python38\lib\site-packages\pexpect\pxssh.py",line 23,in <modu
le>
from pexpect import ExceptionPexpect,TIMEOUT,EOF,spawn
ImportError: cannot import name 'spawn' from 'pexpect' (C:\Users\wolf\AppData\Local\Programs\Python\Python38\lib\si
te-packages\pexpect\__init__.py)
>>>
我发现以下建议使用wexpect
https://stackoverflow.com/a/57528597/13353532
但是,我尝试通过wexpect
尝试SSH的操作无法按预期进行。
>>> import wexpect
>>>
>>> hostname = 'bandit.labs.overthewire.org'
>>> username = 'bandit0'
>>> password = 'bandit0'
>>> port = '2220'
>>>
>>> w = wexpect.spawn(f'ssh {username}@{hostname} -p {port}')
>>> w.send('uptime')
6
>>> print(w.before)
None
>>>
这是服务器中的示例uptime
命令
bandit0@bandit:~$ uptime
16:28:34 up 124 days,20:13,0 users,load average: 0.14,0.23,0.40
bandit0@bandit:~$
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)