how to show mime data using python cgi in windows+apache

I met a problem while using python(2.6) cgi to show a mime data in windows(apache). For example, to show a image, here is my code:

#!E:/program files/Python26/python.exe
# -*- coding: UTF-8 -*-
data = open('logo.png','rb').read()
print 'Content-Type:image/png;Content-Disposition:attachment;filename=logo.png\n'
print data

But it dose not work in windows(xp or 7)+apache or IIS. (I try to write these code in diferent way, and also try other file format, jpg and rar, but no correct output, the output data seems to be disorder in the begining lines.)

And I test these code in linux+apache, and it is Ok!

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
data = open('logo.png','rb').read()
print 'Content-Type:image/png;Content-Disposition:attachment;filename=logo.png\n'
print data

I just feel confused why it does not work in windows. Could anybody give me some help and advice?


One newline between each header. Two newlines between the headers and the body. And watch your line endings.

print 'Content-Type:image/png'
print 'Content-Disposition:attachment;filename=logo.png'

Need Your Help

how can I detect eye corner in eye image using MATLAB?

matlab image-processing computer-vision

I'm trying to estimate gaze direction. at the first step I've extracted the iris location. at the second step I have to detect eye corners. I've tried this code:

How to edit request host headers in c# through web request?

c# .net webrequest

When i'm trying to edit the Host key on Request.Headers under console application i'm getting exception that says:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.