CGI and HTTP Header Location redirects

Derek Basch dbasch at yahoo.com
Thu Feb 3 19:27:19 EST 2005


Hello,

I have been dealing with some strange behavior using CGI, python and an HTTP
Header "Location:" redirect on an Apache 1.3 server.

If I call a CGI script and perform a "Location:" redirect the script seems to
silently run off the tracks immediately after the redirect. For example "0.xml"
and "1.xml" are created when there is no redirect and only "0.xml" is created
when a redirect does occur (see below).

Also, after enabling suEXEC on the apache server the script executes perfectly
with the redirect. Can anyone explain this behavior? I would guess that it is
related to apache user rights but I can't find any reference to such problems
via Google.

Thanks everyone!,
Derek Basch

-------------------------------------------------

#! /usr/bin/python

import sys
import cgitb

class Trainer:
		
	def train(self):
		fs = open("/tmp/0.xml", "w")
		fs.close()
##		print "Location: " + "http://www.yahoo.com" + "\n\n"
		sys.stdout.flush()
		fs = open("/tmp/1.xml", "w")
		fs.close()

def main():
	try:
		cgitb.enable()		
		trainer = Trainer()
		trainer.train()

	except Exception, inst:
		cgitb.handler()
	
if __name__ == '__main__':
	main()



		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 



More information about the Python-list mailing list