繁体   English   中英

Python pexpect.pxssh.ExceptionPxssh:密码被拒绝

[英]Python pexpect.pxssh.ExceptionPxssh: password refused

以下凭据是正确的。

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
>>> 

您的错误源于您为方法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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM