Re: [Zope] Strange error with Photo Product
Dennis Allison writes:
... container.manage_addProduct.manage_addPhoto(id,title,file,.. ) ... Zope Error Zope has encountered an error while publishing this resource. Error Type: KeyError Error Value: the_file
...
File /var/zope/lib/python/Products/PythonScripts/PythonScript.py, line 302, in _exec (Object: photo_upload) (Info: ({'script': <PythonScript instance at 8b70a88>, 'context': <Folder instance at 8d91b60>, 'container': <Folder instance at 8d91b60>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 8, in photo_upload File /var/zope/lib/python/AccessControl/ZopeGuards.py, line 90, in guarded_getitem File /var/zope/lib/python/ZPublisher/HTTPRequest.py, line 847, in __getitem__ KeyError: (see above) File
Apparently, your "file" in not a "ZPublisher.HTTPRequest.FileUpload" instance. --Dieter
That's what I would have guessed, but when I examine it on arrival to the form that contains the call container.manage_addProduct.manage_addPhoto(id,title,file,.. ) it is of FileUpload type. Moreover it gets installed in the PhotoFolder correctly. The particular code is neither long nor complex. I've reproduced it below. The form, a DTML-Method: ------------------------------------------------------------------------ <dtml-var standard_html_header> <p> <form action="photo_upload" method="POST" enctype="multipart/form-data"> <input type="file" name="the_file" size="30"> <br> <input type=submit name=submit value="Upload Photo"> </form> <p> <dtml-var standard_html_footer> ------------------------------------------------------------------------ The handler, a Python Script: ------------------------------------------------------------------------ request = container.REQUEST RESPONSE = request.RESPONSE # move to photofolder p = container.restrictedTraverse('Photos') if( not p ): raise AssertionError, 'No Place to store Photos' the_id = container.genUID() the_title = 'My Photo' the_file = request['the_file'] p.manage_addProduct['Photo'].manage_addPhoto( the_id, the_title, the_file, engine='PNG') request['RESPONSE'].redirect( request['URL'] ) ------------------------------------------------------------------------ Photos is a PhotoFolder instance, essentially a vanilla instance out of the box without much of anything set. genUID is a Python external method that produces a unique identifier. PNG is installed and functions appears to function properly. Any suggestions/pointer appreciate. This one's got me stumpped. -dra
I *think* photos selection of engines is hardwired to be pil or imagemagick. Robert ----- Original Message ----- From: "Dennis Allison" <allison@sumeru.stanford.EDU> To: <allison@sumeru.stanford.EDU>; <dieter@handshake.de> Cc: <rbickers@logicetc.om>; <zope@zope.org> Sent: Tuesday, July 16, 2002 3:51 AM Subject: Re: [Zope] Strange error with Photo Product
Dennis Allison writes:
... container.manage_addProduct.manage_addPhoto(id,title,file,.. ) ... Zope Error Zope has encountered an error while publishing this resource. Error Type: KeyError Error Value: the_file
...
File /var/zope/lib/python/Products/PythonScripts/PythonScript.py,
line
302, in _exec (Object: photo_upload) (Info: ({'script': <PythonScript instance at 8b70a88>, 'context': <Folder instance at 8d91b60>, 'container': <Folder instance at 8d91b60>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 8, in photo_upload File /var/zope/lib/python/AccessControl/ZopeGuards.py, line 90, in guarded_getitem File /var/zope/lib/python/ZPublisher/HTTPRequest.py, line 847, in __getitem__ KeyError: (see above) File
Apparently, your "file" in not a "ZPublisher.HTTPRequest.FileUpload" instance. --Dieter
That's what I would have guessed, but when I examine it on arrival to the form that contains the call
container.manage_addProduct.manage_addPhoto(id,title,file,.. )
it is of FileUpload type. Moreover it gets installed in the PhotoFolder correctly. The particular code is neither long nor complex. I've reproduced it below.
The form, a DTML-Method: ------------------------------------------------------------------------
<dtml-var standard_html_header> <p> <form action="photo_upload" method="POST" enctype="multipart/form-data"> <input type="file" name="the_file" size="30"> <br> <input type=submit name=submit value="Upload Photo"> </form> <p> <dtml-var standard_html_footer> ------------------------------------------------------------------------
The handler, a Python Script: ------------------------------------------------------------------------
request = container.REQUEST RESPONSE = request.RESPONSE # move to photofolder p = container.restrictedTraverse('Photos') if( not p ): raise AssertionError, 'No Place to store Photos' the_id = container.genUID() the_title = 'My Photo' the_file = request['the_file'] p.manage_addProduct['Photo'].manage_addPhoto( the_id, the_title, the_file, engine='PNG') request['RESPONSE'].redirect( request['URL'] )
------------------------------------------------------------------------
Photos is a PhotoFolder instance, essentially a vanilla instance out of the box without much of anything set. genUID is a Python external method that produces a unique identifier. PNG is installed and functions appears to function properly.
Any suggestions/pointer appreciate. This one's got me stumpped.
-dra
_______________________________________________ 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 )
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Dennis Allison Sent: Monday, July 15, 2002 9:51 PM
Error Type: KeyError Error Value: the_file
File Script (Python), line 8, in photo_upload
line 8 >>> the_file = request['the_file'] Try using request.form['the_file'] instead. _______________________ Ron Bickers Logic Etc, Inc.
Dennis Allison writes:
... Zope Error Zope has encountered an error while publishing this resource. Error Type: KeyError Error Value: the_file
...
File /var/zope/lib/python/Products/PythonScripts/PythonScript.py, line 302, in _exec (Object: photo_upload) (Info: ({'script': <PythonScript instance at 8b70a88>, 'context': <Folder instance at 8d91b60>, 'container': <Folder instance at 8d91b60>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 8, in photo_upload File /var/zope/lib/python/AccessControl/ZopeGuards.py, line 90, in guarded_getitem File /var/zope/lib/python/ZPublisher/HTTPRequest.py, line 847, in __getitem__ KeyError: (see above) File ... The form, a DTML-Method:
<dtml-var standard_html_header> <p> <form action="photo_upload" method="POST" enctype="multipart/form-data"> <input type="file" name="the_file" size="30"> <br> <input type=submit name=submit value="Upload Photo"> </form> <p> <dtml-var standard_html_footer> ------------------------------------------------------------------------
The handler, a Python Script: ------------------------------------------------------------------------
request = container.REQUEST RESPONSE = request.RESPONSE # move to photofolder p = container.restrictedTraverse('Photos') if( not p ): raise AssertionError, 'No Place to store Photos' the_id = container.genUID() the_title = 'My Photo' the_file = request['the_file'] p.manage_addProduct['Photo'].manage_addPhoto( the_id, the_title, the_file, engine='PNG') request['RESPONSE'].redirect( request['URL'] ) The problem happens in the redirect!
When the redirect is executed (again by "photo_upload"), the request object is (essentially) empty. Dieter
participants (4)
-
Dennis Allison -
Dieter Maurer -
Robert Rottermann -
Ron Bickers