简体   繁体   中英

return png via python cgi on IIS

I'm trying to return a png image to browser using python cgi on IIS.

I got the same problem with this: Return an image to the browser in python, cgi-bin

but the solutions provided there don't work on my machine.

Here is a brief intro to my situation:

  1. I have a png image on C:\\logs\\demo.png, this image is absolutely fine and can be opened by a visual image viewer;

  2. I have a python script with the code below:

 print 'HTTP/1.1 200 OK' print 'Content-Type:image/png\\n' print file('c:\\\\logs\\\\demo.png', 'rb').read() 

3 . when I visit the corresponding url, nothing returned, and firefox says the image contains errors. The length returned in the response is also very small.

Is there any idea about the problem? I'm getting crazy~

Any reply is appreciated:)

Problem solved.

Finally I found an error in IIS configuration.

The extension mapping should be:

c:\Python27\python.exe -u "%s" "%s"

-u prevents newlines from being converted to Carriage return/ newline combinations which can sometimes cause problems

The article below might be useful for configuration. Very detailed and clear. http://python.net4geeks.com/iiswse.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM