【发布时间】:2018-06-27 02:29:24
【问题描述】:
我有一个脚本在 python 2.7 中运行良好,但现在在 3.6 中它失败了。特别是我此时遇到了问题
下面的代码行正在调用下面的函数:
exec_command(ssh, 'systemctl status myservice', timeout=60)
然后执行函数。在这种情况下,ssh 是使用 paramiko 的 ssh 连接。
def exec_command(ssh, cmd, timeout, want_exitcode=False):
# one channel per command
stdout, stderr = ssh.exec_command(cmd)
# get the shared channel for stdout/stderr
channel = stdout.channel
# indicate that we're not going to write to that channel anymore
channel.shutdown_write()
# read stdout/stderr in order to prevent read block hangs
stdout_chunks = []
stdout_chunks.append(stdout.channel.recv(len(stdout.channel.in_buffer)))
运行时出现以下错误:
文件“path\myscript.py”,第 54 行,在 exec_command ValueError:要解包的值太多(预期为 2) [13340] 执行脚本 myscript 失败
第 54 行是stdout, stderr = ssh.exec_command(cmd)
【问题讨论】:
-
您应该执行
print(ssh.exec_command(cmd))以了解返回了多少值。然后找出你感兴趣的。
标签: python python-3.x