Created on 2011-11-13 21:00 by rhettinger, last changed 2022-04-11 14:57 by admin. This issue is now closed.
Messages (5) |
|
|
msg147572 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2011-11-13 21:00 |
Currently, an XMLRPC client communicating with a server running Python can make Python style calls but exceptions get collapsed into a standard FaultException making it difficult to program in a Pythonic style: proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") try: value = proxy.lookup('somekey') except xmlrpc.client.Fault as err: if err.faultCode == 1 and 'KeyError' in err.faultString: k = re.search(r":.(\w+)' not found$", err.faultString).groups(1) raise KeyError(k) It would be better if we could do this automatically (search for a pure python exception of the same name and raise it instead of a Fault): proxy = xmlrpc.client.ServerProxy("http://localhost:8000/", python_exceptions=True) try: value = proxy.lookup('somekey') except KeyError as e: ... |
|
|
msg196129 - (view) |
Author: PCManticore (Claudiu.Popa) *  |
Date: 2013-08-25 13:04 |
Here's a basic patch. I have two issues with it: the flag name used for enabling the exceptions seems too verbose (use_python_exceptions, I'm opened to new suggestions) and I don't know if the fallback to Fault exception if the remote exception is not known is the best way. |
|
|
msg196130 - (view) |
Author: Donald Stufft (dstufft) *  |
Date: 2013-08-25 13:16 |
-1 This essentially gives the ability for an XMLRPC server to crash any python code that interfaces with them unless you catch _every_ single exception including ones like SystemExit, KeyboardInterupt, SyntaxError, StopIteration etc. An XMLRPC server is not a trusted resources and providing this option is akin to providing an option to unpickle arbitrary data received over the wire as well. |
|
|
msg196172 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2013-08-26 02:21 |
Do you have a suggestion for white-listing or a fault-to-exception mapper? The current API makes faults difficult to use in Python. |
|
|
msg196175 - (view) |
Author: Donald Stufft (dstufft) *  |
Date: 2013-08-26 02:35 |
Well you could possibly whitelist some exceptions although I still think that's ultimately a bad idea because it means to prevent the remote server (or someone in the middle of the connection) from being able to crash your program with an arbitrary exception it means you'd need to catch _all_ the whitelisted exceptions. You could possibly make exception subclasses that subclass the Fault exception _and_ whatever exception the remote server threw so you could get the advantages of both sides. One flaw in this though is that the remote server doesn't need to be in Python, so trying to map errors from the remote server into python exceptions is only going to work *if* the remote server is in Python (and even then only if the exception is a built in one and not any other exception). Yanking the text out of the error message and trying to turn that into an exception is fundamentally wrong I believe. It's a bit like reading the response body of a HTTP request and doing simple string searching to raise arbitrary exceptions (In fact that's basically exactly what it is). |
|
|
History |
|
|
|
Date |
User |
Action |
Args |
2022-04-11 14:57:23 |
admin |
set |
github: 57606 |
2019-08-23 07:01:30 |
rhettinger |
set |
status: open -> closedresolution: rejectedstage: needs patch -> resolved |
2015-03-07 19:58:08 |
Claudiu.Popa |
set |
nosy: - Claudiu.Popa |
2013-08-26 02:35:49 |
dstufft |
set |
messages: + |
2013-08-26 02:21:26 |
rhettinger |
set |
messages: + |
2013-08-25 13:16:21 |
dstufft |
set |
nosy: + dstufftmessages: + |
2013-08-25 13:04:49 |
Claudiu.Popa |
set |
files: + xmlrpc_builtin.patchnosy: + Claudiu.Popamessages: + keywords: + patch |
2011-11-19 13:32:04 |
ezio.melotti |
set |
nosy: + ezio.melottistage: needs patch |
2011-11-18 17:20:13 |
eric.araujo |
set |
nosy: + eric.araujo |
2011-11-13 21:04:53 |
pitrou |
set |
nosy: + loewis, flox |
2011-11-13 21:00:47 |
rhettinger |
set |
priority: normal -> lowcomponents: + Library (Lib) |
2011-11-13 21:00:28 |
rhettinger |
create |
|