Evan Fosmark
Evan Fosmark

Reputation: 101741

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:

distorted Google logo
(source: evanfosmark.com)

Upvotes: 1

Views: 648

Answers (3)

Evan Fosmark
Evan Fosmark

Reputation: 101741

It had to do with \n not being converted properly. I'd like to thank Alex Martelli for pointing me in the right direction.

Upvotes: 1

Anurag Uniyal
Anurag Uniyal

Reputation: 88827

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"

Upvotes: 3

Ken Arnold
Ken Arnold

Reputation: 2013

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.

Upvotes: 0

Related Questions