Image Distortion After Sending Through A Wsgi App In Python
A lot of the time when I send image data over WSGI (using wsgiref), the image comes out distorted. As an example, examine the following: (source: evanfosmark.com)
Solution 1:
As you haven't posted the code, here is a simple code which correctly works with python 2.5 on windows
from wsgiref.simple_server import make_server
def serveImage(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'image/png')]
start_response(status, headers)
return open("about.png", "rb").read()
httpd = make_server('', 8000, serveImage)
httpd.serve_forever()
may be instead of "rb" you are using "r"
Solution 2:
It had to do with \n
not being converted properly. I'd like to thank Alex Martelli for pointing me in the right direction.
Solution 3:
Maybe the result is getting truncated? Try wget
or curl
to fetch the file directly and cmp
it to the original image; that should help debug it. Beyond that, post your full code and environment details even if it's simple.
Post a Comment for "Image Distortion After Sending Through A Wsgi App In Python"