I\'m trying to write a Python script, in pyscripts/find_match.py that will process data received from a POST in an upload.php page, send it to connect.php and then redirect to a
I wish people didn't keep trying to write CGI in 2014.
To redirect in a plain CGI application, you just need to output the destination next to a "Location:" header. However, you have already closed the headers and printed a blank HTML document at the top of your script. Don't do that: it's not only wrong for the redirection, it's also wrong for your alternative path, the form error, since you have already closed the HTML tags.
Instead, start your script like this:
# No printing at the start!
import cgi
...
try:
form = cgi.FieldStorage()
fn = form.getvalue('picture_name')
cat_id = form.getvalue('selected')
except KeyError:
print "Content-type: text/html"
print
print "error"
else:
...
if response.status == 200:
print "Location: response.php"