paramiko.exec_command() not executing and returns “Extra params found in CLI”

懵懂的女人 提交于 2019-11-28 11:21:13

问题


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?

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:

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

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.


回答1:


Based on your latest comment:

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:

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


来源:https://stackoverflow.com/questions/40090445/paramiko-exec-command-not-executing-and-returns-extra-params-found-in-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!