Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python stdout/stderr-ValueError:要解压缩的值太多(应为2个)_Python_Python 3.x - Fatal编程技术网

Python stdout/stderr-ValueError:要解压缩的值太多(应为2个)

Python stdout/stderr-ValueError:要解压缩的值太多(应为2个),python,python-3.x,Python,Python 3.x,我有一个在Python2.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 comman

我有一个在Python2.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)))
运行时,我收到以下错误:

exec_命令中第54行的文件“path\myscript.py” ValueError:要解压缩的值太多(应为2个) [13340]无法执行脚本myscript


第54行是stdout,stderr=ssh.exec_命令(cmd)

您从未说过ssh.exec_命令是什么,但我假设您正在使用paramiko访问某个ssh服务器

正如您在这里的文档中所看到的,此函数返回3个值,而不是2。。。因此,您应该将该行更改为:

stdin, stdout, stderr = ssh.exec_command(cmd)
现在我不知道为什么它以前能工作。也许paramiko api已更改?

您应该执行
打印(ssh.exec_command(cmd))
以了解返回了多少值。然后找出哪些是你感兴趣的。