【问题标题】:Getting permission denied from pexpect python module when doing ssh执行 ssh 时从 pexpect python 模块获得权限被拒绝
【发布时间】: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


    【解决方案1】:

    这是旧版本 pexpect 模块的错误。使用更新模块:

    pip install pexpect --upgrade
    

    【讨论】:

      猜你喜欢
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 2016-04-15
      • 2019-05-15
      • 2015-06-18
      • 2021-07-11
      相关资源
      最近更新 更多