Subprocess check_output returned non-zero exit status 1

This is my python code:

    import subprocess

    import subprocess

The first .check_output() works well, but the second returns this:

    Traceback (most recent call last):
    File "/usr/lib/x86_64-linux-gnu/gedit/plugins/pythonconsole/", line 378, in __run
    r = eval(command, self.namespace, self.namespace)
    File "<string>", line 1, in <module>
    File "/usr/lib/python3.4/", line 616, in check_output
    raise CalledProcessError(retcode, process.args, output=output)
    subprocess.CalledProcessError: Command 'yum' returned non-zero exit status 1

Why does this happen? Is it because ls is the original shell command but yum is the new package? How can I solve this problem?

The command yum that you launch was executed properly. It returns a non zero status which means that an error occured during the processing of the command. You probably want to add some argument to your yum command to fix that.

Your code could show this error this way:

    import subprocess
        subprocess.check_output("dir /f",shell=True,stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as e:
        raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))