在收到图像文件后,我在读取它时遇到问题。
with open(fullpath, 'wb+') as f:
f.write(filevalue)
f.close()
try:
im = Image.open(fullpath, 'r')
im = im.resize((28, 28))
os.remove(fullpath)
im.save(fullpath, 'PNG')
except:
print 'Received non-image file, skipping...'首先打开fullpath并写入接收到的文件值,然后关闭文件。现在文件在磁盘上。
之后,我打开接收到的文件。我已经检查过这个图像文件没有损坏,一个独立的python脚本可以用PIL image类打开它。但是,如果我在接收后立即附加打开文件代码,则会出现以下错误:
File xxxxxx.png could not be opened for reading文件已经写到磁盘上了,为什么打不开?
发布于 2016-05-07 12:36:24
我制作了这个文件的另一个副本,并成功地打开它。这是一个临时的解决方案,尽管开销很大。即使我调用了f.close(),文件似乎也被锁定了,但并没有退出整个程序。
https://stackoverflow.com/questions/37084410
复制相似问题