paramiko.exec_command()未执行,并返回“在CLI中找到额外的参数". [英] paramiko.exec_command() not executing and returns "Extra params found in 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()
执行后返回此消息:
['在CLI中找到额外的参数,不支持此操作,退出CLI会话:\ n']
['Extra params found in CLI, this is not supported, exiting the CLI session:\n']
我在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"; using dumb terminal settings. Extra params found in CLI, this is not supported, exiting the CLI session:
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:
这听起来像不允许SSH服务器上的usrm
帐户的登录外壳以非交互方式运行命令.要解决该问题,您必须像这样使用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\r')
s = chan.recv(4096)
print s
这篇关于paramiko.exec_command()未执行,并返回“在CLI中找到额外的参数".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!