我正在尝试在 cgi-bin 中设置一个 python 脚本,它只返回一个带有 content-type: image/png 的标题并返回图像。我已经尝试打开图像并将其返回,print f.read()
但这不起作用。
编辑:我试图使用的代码是:
print "Content-type: image/png\n\n"
with open("/home/user/tmp/image.png", "r") as f:
print f.read()
这是在 ubuntu 服务器 10.04 上使用 apache。当我在 chrome 中加载页面时,我得到了损坏的图像,当我在 Firefox 中加载页面时,我得到了The image http://localhost/cgi-bin/test.py" cannot be displayed, because it contains errors.