473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to Catch Errors in SimpleXMLRPCServer

I have a pretty simple XMLRPCServer, something along the lines of the
example:

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()

Now what I want to do is catch any errors that happen on requests, and
ideally have them emailed to me. I have the email part all taken care
of, I just need to know how to get at the exceptions.

Thanks in advance for any help,

Greg

Sep 27 '07 #1
6 1885
gr********@gmail.com a écrit :
I have a pretty simple XMLRPCServer, something along the lines of the
example:

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()

Now what I want to do is catch any errors that happen on requests, and
ideally have them emailed to me. I have the email part all taken care
of, I just need to know how to get at the exceptions.
Q&D :

try:
server.serve_forever()
except Exception, e:
mail_me_the_exception(e)
raise
Sep 27 '07 #2
Instead of register_function, use register_instance and provide a
_dispatch method in that instance that handles your exception logging.

Pseudo:

class MyCalls(object):
def _dispatch(self, method, args):
try:
self.getattr(self, method)(*args)
except:
handle_logging()

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(MyCalls())
server.serve_forever()

There might be an easier way... but this works for me.

-Jeff

On 9/27/07, gr********@gmail.com <gr********@gmail.comwrote:
I have a pretty simple XMLRPCServer, something along the lines of the
example:

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()

Now what I want to do is catch any errors that happen on requests, and
ideally have them emailed to me. I have the email part all taken care
of, I just need to know how to get at the exceptions.

Thanks in advance for any help,

Greg

--
http://mail.python.org/mailman/listinfo/python-list
Sep 27 '07 #3
getattr, not self.getattr.

On 9/27/07, Jeff McNeil <je**@jmcneil.netwrote:
Instead of register_function, use register_instance and provide a
_dispatch method in that instance that handles your exception logging.

Pseudo:

class MyCalls(object):
def _dispatch(self, method, args):
try:
self.getattr(self, method)(*args)
except:
handle_logging()

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(MyCalls())
server.serve_forever()

There might be an easier way... but this works for me.

-Jeff

On 9/27/07, gr********@gmail.com <gr********@gmail.comwrote:
I have a pretty simple XMLRPCServer, something along the lines of the
example:

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()

Now what I want to do is catch any errors that happen on requests, and
ideally have them emailed to me. I have the email part all taken care
of, I just need to know how to get at the exceptions.

Thanks in advance for any help,

Greg

--
http://mail.python.org/mailman/listinfo/python-list
Sep 27 '07 #4
On Sep 27, 3:55 pm, "Jeff McNeil" <j...@jmcneil.netwrote:
Instead of register_function, use register_instance and provide a
_dispatch method in that instance that handles your exception logging.

Pseudo:

class MyCalls(object):
def _dispatch(self, method, args):
try:
self.getattr(self, method)(*args)
except:
handle_logging()

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(MyCalls())
server.serve_forever()

There might be an easier way... but this works for me.
I wonder if there is something wrong with that. I get this error on
calling ever method:

Fault 1: 'exceptions.TypeError:cannot marshal None unless allow_none
is enabled' but I can't see anywhere None would be coming from.

-Greg
Sep 27 '07 #5
Yeah, that code was out of memory and I didn't test it, my apologies.
Need to actually return a value from _dispatch.

class MyCalls(object):
def _dispatch(self, method, args):
try:
return getattr(self, method)(*args)
except:
handle_logging()

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(MyCalls())
server.serve_forever()

-Jeff
On 9/27

On 9/27/07, gr********@gmail.com <gr********@gmail.comwrote:
On Sep 27, 3:55 pm, "Jeff McNeil" <j...@jmcneil.netwrote:
Instead of register_function, use register_instance and provide a
_dispatch method in that instance that handles your exception logging.

Pseudo:

class MyCalls(object):
def _dispatch(self, method, args):
try:
self.getattr(self, method)(*args)
except:
handle_logging()

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(MyCalls())
server.serve_forever()

There might be an easier way... but this works for me.

I wonder if there is something wrong with that. I get this error on
calling ever method:

Fault 1: 'exceptions.TypeError:cannot marshal None unless allow_none
is enabled' but I can't see anywhere None would be coming from.

-Greg
--
http://mail.python.org/mailman/listinfo/python-list
Sep 27 '07 #6
On Sep 27, 5:08 pm, "Jeff McNeil" <j...@jmcneil.netwrote:
Yeah, that code was out of memory and I didn't test it, my apologies.
Need to actually return a value from _dispatch.

class MyCalls(object):
def _dispatch(self, method, args):
try:
return getattr(self, method)(*args)
except:
handle_logging()

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(MyCalls())
server.serve_forever()
Thanks, that works. I'm not sure why I didn't notice it wasn't
returning anything.

-Greg
Sep 28 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Thomas G. Apostolou | last post by:
Hello all, I use Python 2.3.3 and try to patch SimpleXMLRPCServer.py with the patch i got from Python.org. so after changing to the directory where both SimpleXMLRPCServer.py and...
0
by: JDF | last post by:
I am trying to create a Windows service using SimpleXMLRPCServer and win32serviceutil. The service itself seems to be working properly (starts, stops, etc) and I can connect using an XMLRPC client...
3
by: Achim Domma | last post by:
Hi, is SimpleXMLRPCServer multithreaded or how does it handle multiple clients? I want to implement a simple server which will be queried by multiple processes for work to be done. The server...
1
by: getafixx | last post by:
Hello everyone, We have a linux server (Fedora core 7, default install, firewall turned off) and a bunch of windows XP machines on network/domain. All machines are visible and I can get to both...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.