M.Morshed
M.Morshed

Reputation: 13

subprocess.check_output gives windows error

I was trying to run this file named develop.py written in python. But it gives error. Here is my code:

import base64
import getpass
import os
import subprocess
import sys

credentials = subprocess.check_output([
    'openssl',
    'aes-256-cbc',
    '-d',
    '-in',
    'credentials.development'
    ], shell=True)

env = os.environ.copy()
env['CREDENTIALS'] = credentials
env['CONFIG'] = 'config.yaml.development'
env['ENVIRONMENT'] = 'development'

subprocess.check_call(['grunt', 'web:develop'], env=env)

Here is the result when I run the file:

 E:\QA\QA>python develop.py
    'openssl' is not recognized as an internal or external command,
    operable program or batch file.
    Traceback (most recent call last):
        File "develop.py", line 13, in <module>
           ], shell=True)
        File "C:\Python27\lib\subprocess.py", line 219, in check_output
            raise CalledProcessError(retcode, cmd, output=output)
        subprocess.CalledProcessError: Command '['openssl', 'aes-256-cbc', 
 '-d', '-in', 'credentials.development']' returned non-zero exit status 1

Environment:
Windows 10 (64 bit)
Python 2.7

How to fix this ??

Upvotes: 1

Views: 1028

Answers (2)

Skiller Dz
Skiller Dz

Reputation: 963

that mean One of this Commandes :

'openssl',
'aes-256-cbc',
'-d',
'-in',
'credentials.development'

dont Exist in openssl

But if you try this:

import base64
import getpass
import os
import subprocess
import sys


credentials = subprocess.check_output(['dir'], shell=True)
env = os.environ.copy()
env['CREDENTIALS'] = credentials
env['CONFIG'] = 'config.yaml.development'
env['ENVIRONMENT'] = 'development'
subprocess.check_call(['grunt', 'web:develop'], env=env)

with dir , it will work perfectly bcz the Command exist

Upvotes: 1

Xantium
Xantium

Reputation: 11603

I think this is a path problem rather than a Python problem. The error mentioned is found when Windows cannot find the command you are after.

In this case the command openssl.

If openssl is not added to path or a file path to it is not specified then it would produce this error.

You should therefore check that the path has been added to path environment variable, then add it if it has not.

Upvotes: 0

Related Questions