Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4093530
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:37:47+00:00 2026-05-20T19:37:47+00:00

I met a problem while using python(2.6) cgi to show a mime data in

  • 0

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:
image.py

#!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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:37:48+00:00Added an answer on May 20, 2026 at 7:37 pm

    Now I know how to solve this problem:

    • For windows+IIS:
      While adding the application mapping(IIS), write C:\Python20\python.exe -u %s %s. I used to write like this c:\Python26\python.exe %s %s, that will create wrong mime data. And “-u” means unbuffered binary stdout and stderr.
    • For windows+Apache:
      Add #!E:/program files/Python26/python.exe -u to the first line of the python script.

    Thank Ignacio Vazquez-Abrams all the same!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have met an interesting problem while implementing the Observer pattern with C++ and
I am learning Python now, and today, I met a problem in http://docs.python.org/release/2.5.4/tut/node8.html 6.1.1
I met an interesting issue about C#. I have code like below. List<Func<int>> actions
In Programming Pearls I have met the following problem. The question is this: print
While considering another problem one question appeared. I do not know how to write
I met some compilation error but do not know what the problem is. The
I have an implementation that just like gmail application, but have met some problem
I met a problem in Xcode. And my problem was similar to this one:
I've met the same problem as this page: http://www.mail-archive.com/pylons-discuss@googlegroups.com/msg14292.html This is the main content
I have a requirement in my application that I think can be met by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.