betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

18 November 2009

Catching Python xmlrpclib Exceptions

Don't you just like these?
 

When using Zope, you don't want to have bare "except:" clauses lying around [1] and when using xmlrpclib in Zope, you will have to guard against whatever connection trouble there may be. Problem is, xmlrpclib seems to sometimes report errors by raising some nonstandard looking exceptions that show up in a traceback like this:

error: (61, 'Connection refused')

Uhm, yeah. In order to catch "error" with a try-except, I should know where it comes from. Lucky me, the traceback mentions that this one is from:

Module httplib, line 630, in connect

Looking there, I see that the code is raising socket.error.

xmlrpclib also has a few errors of its own. I should decide which ones I want to catch, but in general I can do something like this:

from socket import error as socket_error
#... lots of stuff...
try:
    result = server.xmlrpc_update_address_company(id, data)
except (socket_error, xmlrpclib.Fault, \
    xmlrpclib.ProtocolError, xmlrpclib.ResponseError), error_code:
    handle_error(error_code) # whatever you do...

This will get most tracebacks off the back of my users, but of course now the burden of handling the errors is on me. That's the life of the programmer.

[1]because those broad "except:" clauses will also catch ConflictErrors, which Zope should be let to handle by itself. It's also bad style even in general Python.

Posted by betabug at 11:35 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< I didn't go | Main | Apple's Fooled Everybody With Address Book Server 10.6 Description >>
Comments
There are no comments.
Trackbacks
You can trackback to: http://betabug.ch/blogs/ch-athens/1012/tbping
There are no trackbacks.
Leave a comment