System Error from Zope Book Example
On page 157 of the Zope Book is an example of using an external Python script to create thumbnails of graphic images. The main makeThumbnail script works fine. Creating the Python script makeThumbnails and running it generates a System Error "bad argument to internal function." Here's the script I've written, which I am pretty sure matches the one in the book: for image in context.objectValues('Image'): if not image.hasProperty('original_id'): context.makeThumbnail(image.getId()) Here's the dump portion of the error message page:. I'd appreciate any input you have for me. I'm completely bewildered. Traceback (innermost last): File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/Publish.py, line 187, in publish File /home/dshafer/Zope-2.3.3-src/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook (Object: Traversable) File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/Publish.py, line 171, in publish File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: makeThumbnails) File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: makeThumbnails) File /home/dshafer/Zope-2.3.3-src/lib/python/Shared/DC/Scripts/Bindings.py, line 324, in __call__ (Object: makeThumbnails) File /home/dshafer/Zope-2.3.3-src/lib/python/Shared/DC/Scripts/Bindings.py, line 354, in _bindAndExec (Object: makeThumbnails) File /home/dshafer/Zope-2.3.3-src/lib/python/Products/PythonScripts/PythonScript.py, line 336, in _exec (Object: makeThumbnails) (Info: ({'script': <PythonScript instance at 8bb3a30>, 'context': <Folder instance at 89c6c20>, 'container': <Folder instance at 89c6c20>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 4, in makeThumbnails (Object: ssdrawing.jpeg) File /home/dshafer/Zope-2.3.3-src/lib/python/Products/ExternalMethod/ExternalMethod.py, line 269, in __call__ (Object: makeThumbnail) (Info: (('ssdrawing.jpeg',), {}, (128,))) File /home/dshafer/Zope-2.3.3-src/Extensions/Thumbnail.py, line 16, in makeThumbnail (Object: Traversable) SystemError: (see above) -- Dan Shafer, Personal Creativity Trainer and Consultant Trained Hartman Value Profile Analyst http://www.danshafer.com/valueprofile.html
At 10:24 AM +0000 2/17/02, Chris Withers wrote:
Dan Shafer wrote:
(Object: Traversable) SystemError: (see above)
You cut off the 'above' ;-)
Wow. I thought I had written that in my main email message. Perhaps not. For the sake of completeness (with apologies to the list for duplicating the entire thing), here's what it says at the top of the error page: Error Type: SystemError Error Value: bad argument to internal function and then here's the diagnostic: Traceback (innermost last): File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/Publish.py, line 187, in publish File /home/dshafer/Zope-2.3.3-src/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook (Object: Traversable) File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/Publish.py, line 171, in publish File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: makeThumbnails) File /home/dshafer/Zope-2.3.3-src/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: makeThumbnails) File /home/dshafer/Zope-2.3.3-src/lib/python/Shared/DC/Scripts/Bindings.py, line 324, in __call__ (Object: makeThumbnails) File /home/dshafer/Zope-2.3.3-src/lib/python/Shared/DC/Scripts/Bindings.py, line 354, in _bindAndExec (Object: makeThumbnails) File /home/dshafer/Zope-2.3.3-src/lib/python/Products/PythonScripts/PythonScript.py, line 336, in _exec (Object: makeThumbnails) (Info: ({'script': <PythonScript instance at 8bb3a30>, 'context': <Folder instance at 89c6c20>, 'container': <Folder instance at 89c6c20>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 4, in makeThumbnails (Object: ssdrawing.jpeg) File /home/dshafer/Zope-2.3.3-src/lib/python/Products/ExternalMethod/ExternalMethod.py, line 269, in __call__ (Object: makeThumbnail) (Info: (('ssdrawing.jpeg',), {}, (128,))) File /home/dshafer/Zope-2.3.3-src/Extensions/Thumbnail.py, line 16, in makeThumbnail (Object: Traversable) SystemError: (see above)
If you can paste it from the error page we might be able to help...
cheers,
Chris
-- Dan Shafer, Personal Creativity Trainer and Consultant Trained Hartman Value Profile Analyst http://www.danshafer.com/valueprofile.html
At 7:48 AM +0000 2/18/02, Chris Withers wrote:
Dan Shafer wrote:
File /home/dshafer/Zope-2.3.3-src/Extensions/Thumbnail.py, line 16, in makeThumbnail
Can you paste the code from Thumbnail.py here?
(specifically, lines 10-20 ;-)
Sure. Sorry. I had done this in my original message and in an effort to conserve bandwidth I guess I made it harder for people to help. Sigh. Here's the code; I've eliminated the docstring so the first executable line in the function appears on line 10 of the original code. def makeThumbnail(self, original_id, size=128) from PIL import Image from cStringIO import StringIO import os.path # create a thumbnail image file original_image=getattr(self, original_id) original_file=StringIO(original_image.data) image=Image.open(original_file) image=image.convert('RGB') image.thumbnail((size,size)) thumbnail_file=StringIO() image.save(thumbnail_file, "JPEG") thumbnail_file.seek(0) # create an id for the thumbnail path, ext=os.path.splitext(original_id) thumbnail_id=path + '.thumb.jpg' #if there's an old thumbnail, delete it if thumbnail_id in self.objectIds(): self.manage_delObjects(thumbnail_id) # create the Zope image object self.manage_addProduct('OFSP').manage_addImage(thumbnail_id, thumbnail_file, 'thumbnail_image') thumbnail_image=getattr(self, thumbnail_id) # set the 'original_id' property thumbnail_image.manage_addProperty('original_id', original_id, 'string')
cheers,
Chris
-- Dan Shafer, Personal Creativity Trainer and Consultant Trained Hartman Value Profile Analyst http://www.danshafer.com/valueprofile.html
Dan Shafer wrote:
def makeThumbnail(self, original_id, size=128)
from PIL import Image from cStringIO import StringIO import os.path
# create a thumbnail image file original_image=getattr(self, original_id) original_file=StringIO(original_image.data)
So, this is the line with the bug. What's data? What's original_image? I suspect data is of a type the StringIO doesn't like. You sure you haven't got a typo here? cheers, Chris
At 5:20 PM +0000 2/18/02, Chris Withers wrote:
Dan Shafer wrote:
def makeThumbnail(self, original_id, size=128)
from PIL import Image from cStringIO import StringIO import os.path
# create a thumbnail image file original_image=getattr(self, original_id) original_file=StringIO(original_image.data)
So, this is the line with the bug.
What's data? What's original_image? I suspect data is of a type the StringIO doesn't like. You sure you haven't got a typo here?
The makeThumbnail script runs fine when executed directly in a URL. Works flawlessly every time. Only when I call it from the script that attempts to iterate over all the images in a directory and create thumbnails to I encounter the bug I reported. So I don't _think_ it's a typo here. I did submit a followup to my original report in which I indicated that if I call this script inside a folder lower in the object structure than where the script is defined, I get a different result than if I execute it from the level where the script is. I'm guessing at this point that there is something strange about the images I'm processing or their names or some such. But since I'm just copying stuff out of the Zope Book, I'm really sort of clueless. I appreciate your continuing efforts to help.
cheers,
Chris
-- Dan Shafer, Personal Creativity Trainer and Consultant Trained Hartman Value Profile Analyst http://www.danshafer.com/valueprofile.html
Chris Withers writes:
Dan Shafer wrote:
def makeThumbnail(self, original_id, size=128)
from PIL import Image from cStringIO import StringIO import os.path
# create a thumbnail image file original_image=getattr(self, original_id) original_file=StringIO(original_image.data)
So, this is the line with the bug. This almost surely is the large image bug already discussed and solved in the mailing list!
When image is sufficiently large, "image.data" is no longer a string but a complex object. Fix: use "str(original_image.data)" rather than "original_image.data)". If you can, fix the buggy example, too. Dieter
Dan, Put a print statement like so above the line: original_file=StringIO(original_image.data) that reads: print type(original_image.data) And let us know the results of the iteration on which it fails. ... passing something "wrong" into StringIO seems to be what's breaking your code. ----- Original Message ----- From: "Dan Shafer" <dan@gui.com> To: "Chris Withers" <chrisw@nipltd.com> Cc: <zope@zope.org> Sent: Monday, February 18, 2002 12:06 PM Subject: Re: [Zope] System Error from Zope Book Example
At 7:48 AM +0000 2/18/02, Chris Withers wrote:
Dan Shafer wrote:
File /home/dshafer/Zope-2.3.3-src/Extensions/Thumbnail.py, line 16, in makeThumbnail
Can you paste the code from Thumbnail.py here?
(specifically, lines 10-20 ;-)
Sure. Sorry. I had done this in my original message and in an effort to conserve bandwidth I guess I made it harder for people to help.
Sigh.
Here's the code; I've eliminated the docstring so the first executable line in the function appears on line 10 of the original code.
def makeThumbnail(self, original_id, size=128)
from PIL import Image from cStringIO import StringIO import os.path
# create a thumbnail image file original_image=getattr(self, original_id) original_file=StringIO(original_image.data) image=Image.open(original_file) image=image.convert('RGB') image.thumbnail((size,size)) thumbnail_file=StringIO() image.save(thumbnail_file, "JPEG") thumbnail_file.seek(0)
# create an id for the thumbnail path, ext=os.path.splitext(original_id) thumbnail_id=path + '.thumb.jpg'
#if there's an old thumbnail, delete it if thumbnail_id in self.objectIds(): self.manage_delObjects(thumbnail_id)
# create the Zope image object self.manage_addProduct('OFSP').manage_addImage(thumbnail_id, thumbnail_file, 'thumbnail_image') thumbnail_image=getattr(self, thumbnail_id)
# set the 'original_id' property thumbnail_image.manage_addProperty('original_id', original_id, 'string')
cheers,
Chris
-- Dan Shafer, Personal Creativity Trainer and Consultant Trained Hartman Value Profile Analyst http://www.danshafer.com/valueprofile.html
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
At 12:59 PM -0500 2/18/02, Chris McDonough wrote:
Dan,
Put a print statement like so above the line:
original_file=StringIO(original_image.data)
that reads:
print type(original_image.data)
And let us know the results of the iteration on which it fails.
... passing something "wrong" into StringIO seems to be what's breaking your code.
Nothing ever prints. Not sure where it _would_ print. But the error persists. It's obvious to me either that I just don't get something fundamental about Zope and how it deals with scripts and External Methods or there's some kind of major flaw in the scripts in the Zope Book that I am too inexperienced to dope out. The earlier error I reported (bad argument to internal function) disappeared when I deleted the JPEG it was processing at the time. Must have been something wrong with it, though it displayed just fine. The thing is, the scripts I'm talking about actually run. They create the thumbnail(s). Then they cause an error. The new error (which is the second one I reported last week) says that I'm trying to download a CGI application. This error arises _after_ the thumbnails are created. This error occurs on all browsers and all platforms that I can test. i'm going to test with a small, known-working external script later today and see if this is a config problem of some sort. But I've already concluded one thing: external scripts are too hard to use because there's no way to debug them.
----- Original Message ----- From: "Dan Shafer" <dan@gui.com> To: "Chris Withers" <chrisw@nipltd.com> Cc: <zope@zope.org> Sent: Monday, February 18, 2002 12:06 PM Subject: Re: [Zope] System Error from Zope Book Example
At 7:48 AM +0000 2/18/02, Chris Withers wrote:
Dan Shafer wrote:
File /home/dshafer/Zope-2.3.3-src/Extensions/Thumbnail.py, line 16, in makeThumbnail
Can you paste the code from Thumbnail.py here?
(specifically, lines 10-20 ;-)
Sure. Sorry. I had done this in my original message and in an effort to conserve bandwidth I guess I made it harder for people to help.
Sigh.
Here's the code; I've eliminated the docstring so the first executable line in the function appears on line 10 of the original code.
def makeThumbnail(self, original_id, size=128)
from PIL import Image from cStringIO import StringIO import os.path
# create a thumbnail image file original_image=getattr(self, original_id) original_file=StringIO(original_image.data) image=Image.open(original_file) image=image.convert('RGB') image.thumbnail((size,size)) thumbnail_file=StringIO() image.save(thumbnail_file, "JPEG") thumbnail_file.seek(0)
# create an id for the thumbnail path, ext=os.path.splitext(original_id) thumbnail_id=path + '.thumb.jpg'
#if there's an old thumbnail, delete it if thumbnail_id in self.objectIds(): self.manage_delObjects(thumbnail_id)
# create the Zope image object self.manage_addProduct('OFSP').manage_addImage(thumbnail_id, thumbnail_file, 'thumbnail_image') thumbnail_image=getattr(self, thumbnail_id)
# set the 'original_id' property thumbnail_image.manage_addProperty('original_id', original_id, 'string')
cheers,
Chris
-- Dan Shafer, Personal Creativity Trainer and Consultant Trained Hartman Value Profile Analyst http://www.danshafer.com/valueprofile.html
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Dan Shafer, Personal Creativity Trainer and Consultant Trained Hartman Value Profile Analyst http://www.danshafer.com/valueprofile.html
[Dan Shafer]
i'm going to test with a small, known-working external script later today and see if this is a config problem of some sort. But I've already concluded one thing: external scripts are too hard to use because there's no way to debug them.
I don't find that to be the case, if you use Python External Methods. You do have to capture sample data. Then you can get the script to do some self-tests, or log strategic information, and it's often possible to do very well with that information. If the script does not call any Zope objects, then you can make it work independently of Zope, debugging it like any other program. If you make heavy use of Zope objects in your script, though, it's true that it's harder, so I try to avoid that. Use them in Zope and pass the results to the external method whenever you can. Cheers, Tom P
Nothing ever prints. Not sure where it _would_ print. But the error persists.
Sorry, that's my fault. Start Zope up from a console. make sure the "-D" (debug mode) switch is on when you start it up. Things get printed out to the console when Zope starts up and print statements cause output to go to the console as well.
It's obvious to me either that I just don't get something fundamental about Zope and how it deals with scripts and External Methods or there's some kind of major flaw in the scripts in the Zope Book that I am too inexperienced to dope out.
Either is possible. It's my opinion that one of the images that you're iterating over does not have the right kind of "data" attribute. The failure, in other words, is a function of the content.
The earlier error I reported (bad argument to internal function) disappeared when I deleted the JPEG it was processing at the time. Must have been something wrong with it, though it displayed just fine.
Yup, ok, that sounds right.
The thing is, the scripts I'm talking about actually run. They create the thumbnail(s). Then they cause an error. The new error (which is the second one I reported last week) says that I'm trying to download a CGI application. This error arises _after_ the thumbnails are created.
So the problem that started this thread has gone away and now you have another one?
i'm going to test with a small, known-working external script later today and see if this is a config problem of some sort. But I've already concluded one thing: external scripts are too hard to use because there's no way to debug them.
If you start in debug mode and judiciously use print statements or logging calls, they're not too hard to debug. Additionally, unless you want to write a Product, they're just about the only way to do things that require subversion of the security machinery. I wouldn't give up on them so fast. See also http://www.zope.org/Documentation/ZDG/TestingAndDebugging.stx . - C
Hi All, I am newbie here trying to grasp zope. I have an existing website that I am trying to test using Zope. However, I have a lot of java scripts for forms validations , rollover buttons, etc.. I am just curious how should I transfer them to Zope? Are there any examples besides tutorial of zope based websites? Thanks Paul
Pax writes:
I have an existing website that I am trying to test using Zope. However, I have a lot of java scripts for forms validations , rollover buttons, etc.. I am just curious how should I transfer them to Zope? Not at all:
Usually JavaScript is executed in the browser while Zope is running on the server. Client side JavaScript can be uses unchanged when you use Zope on the server.
Are there any examples besides tutorial of zope based websites? Your own privat Zope installation, the various sites on "zope.org", the example in the Zope Book, to name just a few...
Dieter
OK, ZopeLDAP is not doing what I want, so I am going to use python-ldap directly in a script. I make ldap module legal to use in a __init__.py file, I can now use the ldap module on my own... that is, I can so long as I do not attempt to bind to an ldap server. Site Error An error was encountered while publishing this resource. Unauthorized Sorry, a site error occurred. Traceback (innermost last): File /usr/local/zope/2.4.3/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /usr/local/zope/2.4.3/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/zope/2.4.3/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/zope/2.4.3/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: ldap_search) File /usr/local/zope/2.4.3/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: ldap_search) File /usr/local/zope/2.4.3/lib/python/Shared/DC/Scripts/Bindings.py, line 324, in __call__ (Object: ldap_search) File /usr/local/zope/2.4.3/lib/python/Shared/DC/Scripts/Bindings.py, line 354, in _bindAndExec (Object: ldap_search) File /usr/local/zope/2.4.3/lib/python/Products/PythonScripts/PythonScript.py, line 363, in _exec (Object: ldap_search) (Info: ({'script': <PythonScript instance at 1016700>, 'context': <PortalFolder instance at dc1b48>, 'container': <PortalFolder instance at dc1b48>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 4, in ldap_search (Object: guarded_getattr) File /usr/local/zope/2.4.3/lib/python/AccessControl/ZopeGuards.py, line 122, in guarded_getattr File /usr/local/zope/2.4.3/lib/python/AccessControl/SecurityManager.py, line 149, in validate File /usr/local/zope/2.4.3/lib/python/AccessControl/ZopeSecurityPolicy.py, line 172, in validate Unauthorized: simple_bind_s I get this after it tries to reauthenticate me. What the heck is this, and how do I tell Zope security to shut up and leave me alone? Anonymous binds are not permitted by the LDAP server I am trying to connect to, so I have to bind as the directory manager. I will also be adding routines to add, delete, and modify entries in LDAP through Zope, so I need to make sure all my bases are covered here.
Tim Hawes wrote:
OK, ZopeLDAP is not doing what I want, so I am going to use python-ldap directly in a script.
I make ldap module legal to use in a __init__.py file, I can now use the ldap module on my own... that is, I can so long as I do not attempt to bind to an ldap server.
Site Error
An error was encountered while publishing this resource.
Unauthorized
Sorry, a site error occurred.
Traceback (innermost last): ... Unauthorized: simple_bind_s
I get this after it tries to reauthenticate me. What the heck is this, and how do I tell Zope security to shut up and leave me alone? Anonymous binds are not permitted by the LDAP server I am trying to connect to, so I have to bind as the directory manager. I will also be adding routines to add, delete, and modify entries in LDAP through Zope, so I need to make sure all my bases are covered here.
OK, the short answer is that simple_bind_s is trying to be called from a python script, and the security mechanism is saying "woah! I dont know anything about that!". One cheesy way around this is to create an external method to return you a "wrapped" LDAP object that has the special attribute _allow_access_to_unprotected_subobjects_ = 1 set. Alternatively, you can move all of the LDAP-using routines into external methods. Basically, once the LDAP routines pass an object into the Zope environment, Zope will try to see if it has any information about the security on the object. If it cant see any security declarations, it will presume the object's methods are protected by default. -- Matt Kromer Zope Corporation http://www.zope.com/
participants (8)
-
Chris McDonough -
Chris Withers -
Dan Shafer -
Dieter Maurer -
Matthew T. Kromer -
Pax -
Thomas B. Passin -
Tim Hawes