[New-bugs-announce] [issue27281] unpickling an xmlrpc.client.Fault raises TypeError

Uri Okrent report at bugs.python.org
Thu Jun 9 11:09:16 EDT 2016


New submission from Uri Okrent:

Attempting to unpickle an xmlrpc.client.Fault will raise a TypeError:

>>> import xmlrpc.client as xmlrpclib
>>> f = xmlrpclib.Fault(42, 'Test Fault')
>>> import pickle
>>> s = pickle.dumps(f)
>>> pickle.loads(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() missing 2 required positional arguments: 'faultCode' and 'faultString'

Apparently unpickle relies on BaseException's args attribute when reconstructing an Exception class that inherits from BaseException (Fault inherits from Exception).  Unfortunately, Fault implements __init__() and does call the base class constructor, but does not pass its arguments, so Fault.args is always an empty tuple.

Simply passing Fault's arguments to the base class constructor allows it to be unpickled.

I've included a patch for 3.x but the issue is present in 2.x as well (the code and fix are exactly the same except in xmlrpclib.py).

----------
components: Library (Lib)
files: 0001-xmlrpc.client-make-Fault-pickleable.patch
keywords: patch
messages: 268028
nosy: Uri Okrent
priority: normal
severity: normal
status: open
title: unpickling an xmlrpc.client.Fault raises TypeError
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file43321/0001-xmlrpc.client-make-Fault-pickleable.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27281>
_______________________________________


More information about the New-bugs-announce mailing list