【发布时间】:2016-12-07 07:32:09
【问题描述】:
当我从一台服务器到另一台服务器执行简单的 ssh(使用终端)时,它运行良好,但是当我尝试使用 pexpect 模块从我的 python 应用程序中使用 ssh 时,我无法这样做。知道为什么会这样吗?
Traceback (most recent call last):
File "pef.py", line 8, in <module>
s.login(hostname, username, password)
File "/usr/local/pythonbrew/pythons/Python-2.7.10/lib/python2.7/site-packages/pexpect/pxssh.py", line 316, in login
raise ExceptionPxssh('permission denied')
pexpect.pxssh.ExceptionPxssh: permission denied
我正在使用 pexpect 文档中给出的示例
from pexpect import pxssh
import getpass
s = pxssh.pxssh()
s.force_password = True
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login(hostname, username, password)
s.sendline('uptime') # run a command
s.prompt() # match the prompt
print(s.before) # print everything before the prompt.
s.sendline('ls -l')
s.prompt()
print(s.before)
s.sendline('df')
s.prompt()
print(s.before)
s.logout()
【问题讨论】:
标签: python python-2.7 pexpect