[Twisted-Python] unhandled error in example pb_client.py
glyph at twistedmatrix.com
Mon Mar 19 17:26:12 EDT 2012
On Mar 19, 2012, at 3:30 AM, Wolfgang Rohdewald wrote:
> this is twisted 11.0.0 on kubuntu 11.10
> if I call
> cd /usr/share/doc/python-twisted-words/examples/pb_client.py
> python pb_client.py fdfdasfdfdas.com 1000 a b c
> I am getting an unhandled error. Same for servers not answering
> or rejecting.
> how would I have to modify pb_client if I want to catch and
> handle all errors?
"all" errors is a pretty broad category, so you'd have to do a whole bunch of things :).
The type of errors you're talking about are client connection errors. The quickest way to catch those is to make your own subclass of PBClientFactory and implement clientConnectionFailed, which will be called each time there is an error in initially setting up a connection.
> my real-world problem is more complicated: In case of error I
> show a modal Qt4 message box. This gives me interactions between
> twisted and qt4reactor leading to infinite recursion. I can fix that
> for DNS lookup failure and not answering servers by temporarily
> disabling qt4reactor, but for rejecting servers I cannot get rid
> of the unhandled error. But before tackling that, I want to
> understand how I can really catch and handle all errors.
That sounds like a bug in QT, a bug in QT4reactor, or perhaps just the general problem that modal dialog boxes with a blocking API are an inherently bad idea. Without more detail though it's impossible to say what your problem really is. My guess, though, would be to find a modal-dialog-box API that doesn't block or enter a reentrant main loop.
> when that works I will have one more problem: I my case
> I have
> class myClient(pb.PBClientFactory):
> def clientConnectionFailed(self, connector, reason):
> """connection from client to server failed"""
> print 'getErrorMessage:', repr(reason.getErrorMessage())
> which gives me
> "DNS lookup failed: address u'fdksfsfa0s0f.com' not found: [Errno -5] Zu
> diesem Hostnamen geh\xc3\xb6rt keine Adresse."
> so it is translated to German. But pb_client.py returns english messages
> if I insert and use myClient. $LANG is the same for both: de_DE.UTF-8
> so why does pb_client not translate the message?
Because "DNS lookup failed" and "address %r not found" are strings from Twisted, not from your operating system. Twisted does not have any localizations, unfortunately. Localizing all its error messages would be a major project, and a challenging one, as class names appear quite frequently in such messages and their names (such as "Failure") are all in english.
If you were interested in starting to localize Twisted though, I would definitely be interested to hear your thoughts on how it might be done.
More information about the Twisted-Python