Image distortion after sending through a WSGI app in Python

瘦欲@ 提交于 2019-12-24 08:58:47

问题


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)


回答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"




回答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.




回答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.



来源:https://stackoverflow.com/questions/967826/image-distortion-after-sending-through-a-wsgi-app-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!