python - PIL.Image.open() 给出 IOError : cannot identify image file

标签 python stream python-imaging-library stringio

我正在尝试从 Flask 应用程序表单保存 jpg 图像。下面的代码工作正常:

blob = request.files[canvas_key]
blob.stream.seek(0)
data = blob.stream.read()
string_io = cStringIO.StringIO(data)

string_io 的类型为 <cStringIO.StringI object at 0x10bf2bf10> .

但是当我尝试时:Image.open(string_io) ,我收到此错误:IOError: cannot identify image file .

使用stream.seek(0)似乎可以解决 other people 的这个问题,但就我而言,还没有。

最佳答案

感谢@Mark,我将捕获的图像类型从 WebP 更改为 PNG。

关于python - PIL.Image.open() 给出 IOError : cannot identify image file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24024713/

相关文章:

python - 远程热插拔 Python 调试器

python - jinja2.异常.UndefinedError : 'form' is undefined even after passing 'form' in render_template

python - 过滤包含特定字符串的列表

python - 如何根据其他列的值从 pandas 数据框中提取数据?

javascript - 可视化来自远程对等连接的媒体流

java - 写入 servlet 流

javascript - NodeJS 嵌套事件监听器

python - 我可以使用 PIL 获取两个字符的字距调整值吗?

python - 在 Windows 8.1 上的 python 中使用 opencv 和 zbar 来检测二维码

Python PIL - 画圆