【发布时间】:2011-03-13 00:04:42
【问题描述】:
我正在尝试在 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.
【问题讨论】:
-
如果您发布代码,您将获得更好的响应。此外,如果您能描述正在发生的事情,而不仅仅是“这不起作用”,我们将获得更多线索。
标签: python image apache2 cgi-bin