ZPublisher.Client misleading exceptions
We are using ZPublisher.Client to call a "manage_add...." function to create a ZClass instance. We are seeing some strange exceptions. The "manage_add" function works through the web management interface but when called from ZPublisher.Client it creates the instance and then generates an exception. In the following code place, uname, pwd are strings and kw is a dictionary. place is 'http://zopehost/folder/manage_addProduct/Comment/manage_addComment' def go(place,uname,pwd,kw): import Client return(apply(Client.Function(place,username=uname, password=pwd), (), kw)) The desired object is created, however an exception is also generated. Traceback (innermost last): File "<stdin>", line 1, in ? File "autoadd.py", line 14, in addComment go(place,uname,pwd,kw) File "autoadd.py", line 6, in go return(apply(Client.Function(place,username=uname, password=pwd), (), kw)) File "/usr/local/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Client.py", line 225, in __call__ self.handleError(query, ec, em, headers, response) File "/usr/local/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Client.py", line 240, in handleError raise t, RemoteException(t,v,f,l,self.url,query,ec,em,response) bci.ServerError: 302 (File: Unknown Line: Unknown) 302 Moved Temporarily for http://aedmondson:8080/Ed/manage_addProduct/Comment/manage_addComment Whereas creating this object through the ZOPE management interface no error occurs, and we get redirected to the correct management page. Can anyone explain this exception and why it is being generated. On a related note: When trying to create an object with a already-used id (using the code above) through the ZPublisher.Client we get the following exception. Traceback (innermost last): File "<stdin>", line 1, in ? File "autoadd.py", line 14, in addComment go(place,uname,pwd,kw) File "autoadd.py", line 6, in go return(apply(Client.Function(place,username=uname, password=pwd), (), kw)) File "/usr/local/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Client.py", line 225, in __call__ self.handleError(query, ec, em, headers, response) File "/usr/local/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Client.py", line 240, in handleError raise t, RemoteException(t,v,f,l,self.url,query,ec,em,response) bci.NotFound: <HTML><HEAD><TITLE>Ed's discussions test</TITLE></HEAD><BODY BGCOLOR="#FFFFFF"> <TABLE BORDER="0" WIDTH="100%"> <TR VALIGN="TOP"> <TD WIDTH="10%" ALIGN="CENTER"> <IMG SRC="http://aedmondson/p_/ZButton" ALT="Zope"> </TD> <TD WIDTH="90%"> <H2>Zope Err (File: /usr/local/Zope-2.0.1-linux2-x86/lib/python/OFS/ObjectManager.py Line: 209) 400 Bad Request for http://aedmondson:8080/Ed/manage_addProduct/Comment/manage_addComment Whereas through the ZOPE management interface attempting to create an instance with same id produced this: <H2>Zope Error</H2> <P>Zope has encountered an error while publishing this resource. </P> <P> <STRONG>Error Type: Bad Request</STRONG><BR> <STRONG>Error Value: The id 1 is invalid - it is already in use.</STRONG><BR> </P> We fully except to get the error but the error from the web management interface is much more informative. How do we access this useful diagnostics from ZPublisher.Client. Thanks for your help. Thanks, Richard Ed
R.Taylor@eris.dera.gov.uk wrote:
We are using ZPublisher.Client to call a "manage_add...." function to create a ZClass instance. We are seeing some strange exceptions.
The "manage_add" function works through the web management interface but when called from ZPublisher.Client it creates the instance and then generates an exception.
In the following code place, uname, pwd are strings and kw is a dictionary. place is 'http://zopehost/folder/manage_addProduct/Comment/manage_addComment'
def go(place,uname,pwd,kw): import Client return(apply(Client.Function(place,username=uname, password=pwd), (), kw))
The desired object is created, however an exception is also generated.
Traceback (innermost last): File "<stdin>", line 1, in ? File "autoadd.py", line 14, in addComment go(place,uname,pwd,kw) File "autoadd.py", line 6, in go return(apply(Client.Function(place,username=uname, password=pwd), (), kw)) File "/usr/local/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Client.py", line 225, in __call__ self.handleError(query, ec, em, headers, response) File "/usr/local/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Client.py", line 240, in handleError raise t, RemoteException(t,v,f,l,self.url,query,ec,em,response) bci.ServerError: 302 (File: Unknown Line: Unknown) 302 Moved Temporarily for http://aedmondson:8080/Ed/manage_addProduct/Comment/manage_addComment
Whereas creating this object through the ZOPE management interface no error occurs, and we get redirected to the correct management page.
Can anyone explain this exception and why it is being generated.
A redirect is generated (in HTTP) by returning a 302 status code. The client is treatng this as an error. There should probably be an option in the client to treat redirects as success.
On a related note:
When trying to create an object with a already-used id (using the code above) through the ZPublisher.Client we get the following exception.
Traceback (innermost last): File "<stdin>", line 1, in ? File "autoadd.py", line 14, in addComment go(place,uname,pwd,kw) File "autoadd.py", line 6, in go return(apply(Client.Function(place,username=uname, password=pwd), (), kw)) File "/usr/local/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Client.py", line 225, in __call__ self.handleError(query, ec, em, headers, response) File "/usr/local/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Client.py", line 240, in handleError raise t, RemoteException(t,v,f,l,self.url,query,ec,em,response) bci.NotFound: <HTML><HEAD><TITLE>Ed's discussions test</TITLE></HEAD><BODY BGCOLOR="#FFFFFF"> <TABLE BORDER="0" WIDTH="100%"> <TR VALIGN="TOP"> <TD WIDTH="10%" ALIGN="CENTER"> <IMG SRC="http://aedmondson/p_/ZButton" ALT="Zope"> </TD> <TD WIDTH="90%"> <H2>Zope Err (File: /usr/local/Zope-2.0.1-linux2-x86/lib/python/OFS/ObjectManager.py Line: 209) 400 Bad Request for http://aedmondson:8080/Ed/manage_addProduct/Comment/manage_addComment
Whereas through the ZOPE management interface attempting to create an instance with same id produced this:
<H2>Zope Error</H2> <P>Zope has encountered an error while publishing this resource. </P> <P> <STRONG>Error Type: Bad Request</STRONG><BR> <STRONG>Error Value: The id 1 is invalid - it is already in use.</STRONG><BR> </P>
We fully except to get the error but the error from the web management interface is much more informative. How do we access this useful diagnostics from ZPublisher.Client.
Perhaps the client should include the error body when it raises the error. Patches accepted. ;) Jim -- Jim Fulton mailto:jim@digicool.com Python Powered! Technical Director (888) 344-4332 http://www.python.org Digital Creations http://www.digicool.com http://www.zope.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
participants (2)
-
Jim Fulton -
R.Taylor@eris.dera.gov.uk