This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Option for XMLRPC clients to automatically transform Fault exceptions into standard exceptions
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: dstufft, eric.araujo, ezio.melotti, flox, loewis, rhettinger
Priority: low Keywords: patch

Created on 2011-11-13 21:00 by rhettinger, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
xmlrpc_builtin.patch Claudiu.Popa, 2013-08-25 13:04 review
Messages (5)
msg147572 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) 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) * (Python triager) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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:23adminsetgithub: 57606
2019-08-23 07:01:30rhettingersetstatus: open -> closed
resolution: rejected
stage: needs patch -> resolved
2015-03-07 19:58:08Claudiu.Popasetnosy: - Claudiu.Popa
2013-08-26 02:35:49dstufftsetmessages: + msg196175
2013-08-26 02:21:26rhettingersetmessages: + msg196172
2013-08-25 13:16:21dstufftsetnosy: + dstufft
messages: + msg196130
2013-08-25 13:04:49Claudiu.Popasetfiles: + xmlrpc_builtin.patch

nosy: + Claudiu.Popa
messages: + msg196129

keywords: + patch
2011-11-19 13:32:04ezio.melottisetnosy: + ezio.melotti

stage: needs patch
2011-11-18 17:20:13eric.araujosetnosy: + eric.araujo
2011-11-13 21:04:53pitrousetnosy: + loewis, flox
2011-11-13 21:00:47rhettingersetpriority: normal -> low
components: + Library (Lib)
2011-11-13 21:00:28rhettingercreate