paramiko.exec_command() not executing and returns quot;Extra params found in CLIquot;(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 paramserror. 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 中找到的额外参数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:paramiko.exec_command() 未执行并返回“在 CLI 中找到的额外参数"
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
