Errors while running the Thumbnails example code
Hello, i'm trying to run the example code from "The Zope Book": http://www.plope.com/Books/2_7Edition/ScriptingZope.stx#1-5 However, there are several errors. The first error that I get is the following: ,---- | Error Type: NameError | Error Value: global name 'Image' is not defined `---- I looked into the PIL tutorial and found out that they use 'import Image' instead of 'import PIL'. I changed the import statement this way, and this error disappeared, however I got another error, which I cannot explain: ,---- | Error Type: AttributeError | Error Value: StringIO instance has no attribute 'startswith' | | Traceback (innermost last): | | * Module ZPublisher.Publish, line 101, in publish | * Module ZPublisher.mapply, line 88, in mapply | * Module ZPublisher.Publish, line 39, in call_object | * Module Shared.DC.Scripts.Bindings, line 306, in __call__ | * Module Shared.DC.Scripts.Bindings, line 343, in _bindAndExec | * Module Products.PythonScripts.PythonScript, line 323, in _exec | * Module None, line 2, in makeThumbnails | <PythonScript at /Examples/makeThumbnails used for /Examples/Images> | Line 2 | * Module Products.ExternalMethod.ExternalMethod, line 232, in __call__ | __traceback_info__: (('4,7-liter.jpg',), {}, (200,)) | * Module /opt/zope/instance/Extensions/Thumbnail.py, line 26, in makeThumbnail | * Module Image, line 1556, in open | * Module App.ImageFile, line 36, in __init__ | * Module posixpath, line 60, in join | | AttributeError: StringIO instance has no attribute 'startswith' `---- This happens in the following line: ,---- | original_file=StringIO(str(original_image.data)) `---- The most strange thing about it is that if I run the following code outside of zope, everything works: ,---- | import Image | import StringIO | | fp = open("20.jpg") | buffer = fp.read() | im = Image.open(StringIO.StringIO(buffer)) `---- To be sure, I tested this code in zope exactly as above (so that the file is loaded from disk, not from Zope), but got the same error. Any ideas, what's going wrong? Thanks in advance! -- \ / vlad@hashbang.de \/lad http://www.hashbang.de
Vlad Berditchevskiy <vlad@hashbang.de> writes:
This happens in the following line:
,---- | original_file=StringIO(str(original_image.data)) `----
Sorry, I quoted the wrong line. The error is actually happening here: ,---- | image=Image.open(original_file) `---- I also tried to supply the file name directly: ,---- | image = Image.open('/home/vlad/my.jpg') `---- and got almost the same result: Error Value: 'file' object has no attribute 'startswith' -- \ / vlad@hashbang.de \/lad http://www.hashbang.de
Am 09.10.2004, 01:16 Uhr schryb Vlad Berditchevskiy <vlad@hashbang.de>:
I looked into the PIL tutorial and found out that they use 'import Image' instead of 'import PIL'. I changed the import statement this way, and this error disappeared, however I got another error, which I cannot explain:
,---- | Error Type: AttributeError | Error Value: StringIO instance has no attribute 'startswith' | | Traceback (innermost last): | [...] | * Module Image, line 1556, in open | * Module App.ImageFile, line 36, in __init__ | * Module posixpath, line 60, in join | | AttributeError: StringIO instance has no attribute 'startswith' `----
This typically happens when your import fetches the Zope Image Product (lib/python/OFS/Image.py) instead of the PIL Image module. Try "import PIL.Image as Image" instead. Jo. -- internetmanufaktur jo----------------------------- Berlin, Germany |||||||||||||||meder-------------------fon: ++49-30-417 17 63 33 http://www.meder.de/ ------------------- fax: ++49-30-417 17 63 45 Kollwitzstr. 75 ------------------------ mob: ++49-170- 2 98 89 97 10435 Berlin ---------------http://www.meder.de/keys/jo-pubkey.txt
participants (2)
-
Jo Meder -
Vlad Berditchevskiy