pipes python cgi and gnupg

byte8bits at gmail.com byte8bits at gmail.com
Fri Dec 28 22:07:49 EST 2007


I think this is more a GnuPG issue than a Python issue, but I wanted
to post it here as well in case others could offer suggestions:

I can do this from a python cgi script from a browser:

os.system("gpg --version > gpg.out")

However, I cannot do this from a browser:

os.system("echo %s | gpg --batch --password-fd 0 -d %s > d.out"
%(pass, filename))

The output file is produced, but it's zero byte. I want the decrypted
file's content, but the pipe seems to mess things up. The script works
fine when executed from command line. The output file is produced as
expected. When executed by a browser, it does not work as expected...
only produces a zero byte output file. Any tips? I've googled a bit
and experimented for a few nights, still no go.

Thanks,
Brad

Here's the entire script:

#!/usr/local/bin/python

import cgi
import cgitb; cgitb.enable()
import os
import tempfile

print "Content-Type: text/html"
print
print "<TITLE>T</TITLE>"
print "<H1>H</H1>"

form = cgi.FieldStorage()
if not form.has_key("pass"):
   print "Enter password"

filename = "test.gpg"
pass = form.getvalue("pass").strip()
os.system("gpg --version > gpg.out")
os.system("echo %s | gpg --batch --password-fd 0 --decrypt %s > d.out"
%(pass,filename))



More information about the Python-list mailing list