Python 从CGI生成的程序发送stdout作为响应

Python 从CGI生成的程序发送stdout作为响应,python,apache,cgi,Python,Apache,Cgi,我试图在CGI程序中编写一个.zip文件,并将其作为内容响应发送。每当我生成一个打印到stdout的程序时,我就陷入了这样的困境,而这个程序不知何故没有被Apache接受。这似乎与生成一个写入标准输出的程序有关。下面的代码片段再现了这个问题。我总是从Apache中得到以下错误: malformed header from script. Bad header=hello world print ("Content-Type: text/html"); print (""); #pr

我试图在CGI程序中编写一个.zip文件,并将其作为内容响应发送。每当我生成一个打印到stdout的程序时,我就陷入了这样的困境,而这个程序不知何故没有被Apache接受。这似乎与生成一个写入标准输出的程序有关。下面的代码片段再现了这个问题。我总是从Apache中得到以下错误:

malformed header from script. Bad header=hello world  

print ("Content-Type: text/html");  
print ("");  
#print ("hello world");     <-----This works  
os.system("echo hello world");  <-----This doesn't work
脚本中的头格式不正确。坏标题=你好世界 打印(“内容类型:文本/html”); 打印(“”); #打印(“你好世界”) 在调用外部程序之前,请尝试使用sys.stdout.flush()