paramiko.exec_command() 未执行并返回“在 CLI 中找到的额外参数" [英] paramiko.exec_command() not executing and returns "Extra params found in CLI"

查看:40
本文介绍了paramiko.exec_command() 未执行并返回“在 CLI 中找到的额外参数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Paramiko 对服务器进行 ssh 并执行命令.但是 paramiko.exec_command() 返回错误.为什么会这样?

I am trying to ssh a server using Paramiko and execute a command. But the paramiko.exec_command() returns with an error.Why is this happening?

这是我的 Python 脚本:

This is my Python script:

import paramiko

ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.126.141.132', username='usrm', password='passwd')

stdin, stdout, stderr = ssh.exec_command("show chassis")

print(stdout.readlines())

ssh.close()

执行时它会返回以下消息:

When executed it returns with this message:

['在 CLI 中发现额外参数,不支持,退出 CLI 会话: ']

['Extra params found in CLI, this is not supported, exiting the CLI session: ']

我在 Windows 上使用 Python 3.5.2 :: Anaconda 4.1.1(64 位)和 Paramiko.

I am using Python 3.5.2 :: Anaconda 4.1.1 (64-bit) with Paramiko on Windows.

我已经手动尝试了这些命令并且它正在工作.

I have tried the commands manually and it is working.

推荐答案

根据您的最新评论:

我安装了 Cygwin 终端并使用命令对服务器进行 SSH...它出现了 Extra params 错误.我执行的命令:ssh usrm@10.126.141.132 "show chassis",输出:No entry for terminal type "dumb";使用哑终端设置.在 CLI 中发现额外参数,不支持,退出 CLI 会话:

I installed a Cygwin Terminal and SSH'd the server with the command...it came up with the Extra params error. Command I executed: ssh usrm@10.126.141.132 "show chassis", Output: No entry for terminal type "dumb"; using dumb terminal settings. Extra params found in CLI, this is not supported, exiting the CLI session:

好像usrm账号在SSH服务器上的login shell不允许以非交互方式运行命令.要解决问题,您必须像这样使用 invoke_shell():

it sounds like the usrm account's login shell on the SSH server is not allowed to run commands in the non-interactive way. To solve the problem you have to use invoke_shell() like this:

chan = ssh.invoke_shell()
chan.sendall('show chassis
')
s = chan.recv(4096)
print s

这篇关于paramiko.exec_command() 未执行并返回“在 CLI 中找到的额外参数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆