简体   繁体   English

python - pxssh - 登录失败

[英]python - pxssh - failed to login

I'm trying to connect to a server using ssh via the pxssh python library.我正在尝试通过 pxssh python 库使用 ssh 连接到服务器。 Here's my code:这是我的代码:

import pxssh
import getpass
try:
    s = pxssh.pxssh()
    s.force_password = True
    hostname = 'myserverip'
    username = 'username'
    password = 'password'
    s.login (hostname, username, password)
    s.sendline ('get system number')  # run a command
    s.prompt()             # match the prompt
    print s.before         # print everything before the prompt.
    s.logout()
except pxssh.ExceptionPxssh, e:
    print "pxssh failed on login."
    print str(e)

Here is the response I am getting:这是我得到的回应:

pxssh failed on login.
could not set shell prompt
 unset PROMPT_COMMAND

error,09
$ PS1='[PEXPECT]\$ '

error,09
$ set prompt='[PEXPECT]\$ '

error,09
$

Pretty old question but just for posterity. 相当老的问题,但仅用于后代。 (For the one's who would bump in to this like me :) ) (对于那些会像我这样碰到这个的人:))

from pexpect import pxssh
import getpass
try:
    s = pxssh.pxssh()
    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()
except pxssh.ExceptionPxssh as e:
    print("pxssh failed on login.")
    print(e)

which I just yanked from http://pexpect.readthedocs.io/en/latest/api/pxssh.html#pexpect.pxssh.pxssh 我刚刚从http://pexpect.readthedocs.io/en/latest/api/pxssh.html#pexpect.pxssh.pxssh中拉出了

Did you verify the login credentials?您是否验证了登录凭据? The logs indicate that your script didnt clear the first step necessary to get the shell.日志表明您的脚本没有清除获取 shell 所需的第一步。 s.login(hostname, username, password) BTW, you are hardcoding all these arguments. s.login(hostname, username, password) 顺便说一句,您正在硬编码所有这些参数。 Your first problem here is that there is no hostname as 'hostname' which you can logon to on any system, unless alias of 'localhost' or some website/url.这里的第一个问题是没有主机名作为“主机名”,您可以在任何系统上登录,除非是“本地主机”的别名或某些网站/网址。

Note: Use your head before blatantly copying examples.注意:在公然复制示例之前先用头脑。

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

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