首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python Paramiko/SSH错误

Python Paramiko/SSH错误
EN

Stack Overflow用户
提问于 2016-11-08 02:08:22
回答 1查看 943关注 0票数 0

我是Python新手,正在学习SSH的用法。有人能帮我找出错误的原因吗?基本上是尝试从Unix机器通过ssh连接到设备,然后执行一个简单的'show version‘命令并返回/打印其输出

代码语言:javascript
复制
Traceback (most recent call last):
File "ssh.py", line 33, in <module>
ver = node.cmd('show version')
File "/home/xxxx/python/classes/ssh.py", line 17, in cmd
stdin, stdout, stderr = self.node.exec_command(command)
File "/usr/local/lib/python2.6/dist-packages/paramiko/client.py", line 345, in exec_command
chan.exec_command(command)
File "/usr/local/lib/python2.6/dist-packages/paramiko/channel.py", line 60, in _check
return func(self, *args, **kwds)
File "/usr/local/lib/python2.6/dist-packages/paramiko/channel.py", line 229, in exec_command
self._wait_for_event()
File "/usr/local/lib/python2.6/dist-packages/paramiko/channel.py", line 1086, in _wait_for_event
raise e
EOFError

调试器

代码语言:javascript
复制
DEB [20161107-17:37:31.455] thr=1   paramiko.transport: starting thread (client mode): 0x23f2310L
INF [20161107-17:37:31.460] thr=1   paramiko.transport: Connected (version 2.0, client OpenSSH_3.5p1)
DEB [20161107-17:37:31.463] thr=1   paramiko.transport: blah blah
DEB [20161107-17:37:31.463] thr=1   paramiko.transport: Ciphers agreed: local=aes128-cbc, remote=aes128-cbc
DEB [20161107-17:37:31.463] thr=1   paramiko.transport: blah blah
DEB [20161107-17:37:31.466] thr=1   paramiko.transport: Got server p (1024 bits)
DEB [20161107-17:37:31.610] thr=1   paramiko.transport: Switch to new keys ...
DEB [20161107-17:37:31.627] thr=2   paramiko.transport: Adding ssh-rsa host key for as102.lnstb: xxxxxxxxxxx
DEB [20161107-17:37:31.633] thr=1   paramiko.transport: userauth is OK
INF [20161107-17:37:31.669] thr=1   paramiko.transport: Authentication (password) successful!
DEB [20161107-17:37:31.693] thr=2   paramiko.transport: [chan 0] Max packet in: 32768 bytes
DEB [20161107-17:37:31.696] thr=1   paramiko.transport: [chan 0] Max packet out: 32768 bytes
DEB [20161107-17:37:31.696] thr=1   paramiko.transport: Secsh channel 0 opened.
DEB [20161107-17:37:31.704] thr=1   paramiko.transport: EOF in transport thread

代码

代码语言:javascript
复制
class Ssh:

def connect(self, host, user, password):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(host, username = user, password = password)
    self.node = ssh

def cmd(self,command):
     stdin, stdout, stderr = self.node.exec_command(command)
     return stdout.read()

node = Ssh()
node.connect(host,user,pwd)
ver = node.cmd('show version')
print(ver)
EN

回答 1

Stack Overflow用户

发布于 2016-11-08 02:44:18

因此,我在另一台由独立供应商提供的设备上尝试了一下,它可以正常工作。似乎这个特定的供应商需要在paramiko配置中进行一些调整。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40471709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档