Luk*_*urn 6 python asp.net jpeg
我有一个image.asp使用Python 的文件,我试图打开一个JPEG图像并将其写入响应,以便可以从相关链接中检索它.我目前有什么:
<%@ LANGUAGE = Python%>
<%
path = "path/to/image.jpg"
with open(path, 'rb') as f:
jpg = f.read()
Response.ContentType = "image/jpeg"
Response.WriteBinary(jpg)
%>
Run Code Online (Sandbox Code Playgroud)
在浏览器中,这将返回以下错误:
The image "url/to/image.asp" cannot be displayed because it contains errors.
Run Code Online (Sandbox Code Playgroud)
我怀疑问题是我只是没有正确地写jpg文件的内容.我需要修理什么?
你的问题在这里:
with open(url, 'rb') as f:
Run Code Online (Sandbox Code Playgroud)
包含路径的变量被命名为路径,而不是 url。
使其为:
with open(path, 'rb') as f:
Run Code Online (Sandbox Code Playgroud)
效果会更好。
| 归档时间: |
|
| 查看次数: |
179 次 |
| 最近记录: |