Problem scenario
You are automating a Linux infrastructure task with Python using subprocess calls. You get this error "subprocess.CalledProcessError: Command '…' returned non-zero exit status 1", what should you do?
Solution
Run the Linux command without Python. Then run echo $?
to determine the exit code. If you see a 1, that means Python notices this command is not considered to have run successfully. The solution should be to break down the processing into atomic Python commands. Try to use Python as much as possible for whatever you were doing. Make sure the Linux command returns an exit code of 0 every time the command is run.
Use the env > /path/to/analyze.txt
command. When Python runs, the env variables will be different from the commands you interactively run. Therefore the contents of the env command should help you.