Unsupportedoperation: Fileno - How To Fix This Python Dependency Mess?
Solution 1:
BytesIO
objects raise UnsupportedOperation
(rather than AttributeError
which StringIO
does) when their fileno
method is called that exception wasn't handled as it should be.
This was fixed in Pillow 3.0.0 by this commit https://github.com/python-pillow/Pillow/commit/197885164b22f82653af514e66c76f4b778c0b1b by catching the exception. The following is the fix. The rest of that commit are changes to the test suite.
In PIL/ImageFile.py
:
@@ -29,6 +29,7 @@import Image
import traceback, os
+import io
MAXBLOCK = 65536 @@ -475,7 +476,7 @@ def _save(im, fp, tile):try:
fh = fp.fileno()
fp.flush()
- except AttributeError:
+ except (AttributeError, io.UnsupportedOperation):
# compress to Python file-compatible objectfor e, b, o, a in tile:
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
You could simply patch 1.7.8 to handle the exception.
Solution 2:
I finally managed to fix things. The reason I downgraded pillow from 3.0.0 to 1.7.8, is because those where the only two versions I saw listed on the Pillow Pypi package index. I finally remembered that I had one more server on which I once tested this code and there it was still working. A quick pip freeze
told me that it had Pillow version 2.3.0
installed. So after installing that on my dev server things worked beautifully again.
So what have I learned from this? Use pip freeze
!
Post a Comment for "Unsupportedoperation: Fileno - How To Fix This Python Dependency Mess?"