【问题标题】:Python pexpect.pxssh.ExceptionPxssh: password refusedPython pexpect.pxssh.ExceptionPxssh:密码被拒绝
【发布时间】:2020-12-27 21:15:41
【问题描述】:

以下凭据正确。

wolf@linux:~$ sshpass -p bandit0 ssh bandit0@bandit.labs.overthewire.org -p 2220
This is a OverTheWire game server.

但是它不适用于 Python pexpect.pxssh

>>> from pexpect import pxssh
>>> s = pxssh.pxssh()
>>> hostname = 'bandit.labs.overthewire.org'
>>> username = 'bandit0'
>>> password = 'bandit0'
>>> port = '2220'
>>> s.login(hostname, username, password, port)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pexpect/pxssh.py", line 402, in login
    raise ExceptionPxssh('password refused')
pexpect.pxssh.ExceptionPxssh: password refused
>>> 

【问题讨论】:

  • 我怀疑您在 login 方法中给定的位置参数导致了问题。根据documentation的方法,试试s.login(hostname, username, password, port=port),效果更好。
  • 感谢@HampusLarsson,它有效!快来回答吧

标签: python pexpect pxssh


【解决方案1】:

您的错误源于您为方法pexpect.pxssh.pxssh.login 提供的位置参数。

根据文档,该方法的前四个位置参数是:

server, username=None, password='', terminal_type='ansi'

因此,当您调用 s.login(hostname, username, password, port) 时,您将 terminal_type 设置为端口号。

如果您将最后一个参数更改为关键字参数,则端口将正确设置:

s.login(hostname, username, password, port=port)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 2019-04-28
    • 2018-04-12
    • 2015-02-18
    • 1970-01-01
    • 2020-09-03
    相关资源
    最近更新 更多