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

问题描述

以下凭据正确。

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,port=port)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...