1

I am running openssl command to create a self signed certificate inside Python script. Facing Unexpected "(" syntax error.

import os

os.system('openssl req -x509 -newkey rsa:4096 -sha256 -days 7300 -nodes -keyout istio_gw.key -out istio_gw.crt -subj "/CN=csd.nokia.com/O=Nokia" -extensions san -config <( echo "[req]"; echo"distinguished_name=req";)')

2 Answers 2

2

It's a bashism, so you need to prepend it with bash -c:

shell_command = 'openssl req -x509 -newkey rsa:4096 -sha256 -days 7300 -nodes -keyout istio_gw.key -out istio_gw.crt -subj "/CN=csd.nokia.com/O=Nokia" -extensions san -config <( echo "[req]"; echo"distinguished_name=req";)'

os.system("bash -c '{}'".format(shell_command))

But more importantly, you should be using subprocess instead of os.system

To use subprocess, you should be able to use the shell=True argument:

subprocess.check_output(shell_command, shell=True)
Sign up to request clarification or add additional context in comments.

Comments

0

With SubProcess :

import subprocess

from subprocess import Popen, PIPE

shell_command = 'openssl req -x509 -newkey rsa:4096 -sha256 -days 7300 -nodes -keyout istio_gw.key -out istio_gw.crt -subj "/CN=csd.nokia.com/O=Nokia" -extensions san -config <( echo "[req]"; echo "distinguished_name=req"; echo "[san]"; echo "subjectAltName=DNS:*.nokia.com")'

p = Popen("bash -c '{}'".format(shell_command), shell=True, bufsize=-1, stderr=PIPE, stdout=PIPE)

out,err = p.communicate()

print(out)

print(err)

1 Comment

I'm not sure you need to use both bash -c and shell=True, see my edited answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.