I have a python file which I'd like to use as part of a Github Action. It uses subprocess.run(). For some reason, this fails in a Github Action.
Here is the code in question, where "arg_method" is the string "decrypt":
for file in files_to_handle:
process = subprocess.run(
"--location=" + hidden,
"--keyring=" + hidden,
"--key=" + hidden,
"--plaintext-file=" + hidden,
"--ciphertext-file=" + hidden
The github action always fails on this step. Here is the output:
Run python python_script_name_hidden.py --method=decrypt --env=production --yes ERROR: (gcloud) Command name argument expected.
It appears the arguments are not being passed to the subprocess. It is not getting as far as "kms"
Any advice on how to fix this?
Solved! Solved! Go to Solution.
Hey all. I solved this. Running this on a Linux server revealed it wasn't working everywhere.
I changed the script to the following, which seems to have worked:
for file in files_to_handle: process = subprocess.Popen( [ "gcloud", "kms", arg_method, "--location=" + hidden, "--keyring=" + hidden, "--key=" + hidden, "--plaintext-file=" + hidden, "--ciphertext-file=" + hidden ], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) output, error = process.communicate() if process.returncode != 0: raise Exception("File handling failed %d %s %s" % (process.returncode, output, error))
I thought I'd update this incase anyone has a similar issue
Thanks for the quick reply. I ran this on another machine and was able to replicate the issue. I solved this by using subprocess.Popen as opposed to subprocess.run.
Thanks for the suggestions. I marked the previous reply as a solution to avoid any confusion.
Yeah, I didn't noticed your previous reply until I submitted my reply, so I changed my reply.
Anyway, thanks again for share your experiences here. I believe this can help more people who have the same/similar problems.