在 Python 中通过 WSGI 应用程序发送后的图像失真 [英] Image distortion after sending through a WSGI app in Python
本文介绍了在 Python 中通过 WSGI 应用程序发送后的图像失真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
很多时候,当我通过 WSGI(使用 wsgiref
)发送图像数据时,图像会失真.例如,检查以下内容:
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:
(来源:evanfosmark.com)
推荐答案
由于您还没有发布代码,这里是一个可以正常工作的简单代码在 Windows 上使用 python 2.5
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()
您可能使用的是r"而不是rb"
may be instead of "rb" you are using "r"
这篇关于在 Python 中通过 WSGI 应用程序发送后的图像失真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文