diff --git a/canonicaljson.py b/canonicaljson.py index 8dee682..5a4c2ef 100644 --- a/canonicaljson.py +++ b/canonicaljson.py @@ -26,7 +26,13 @@ def _default(obj): if type(obj) is frozendict: # fishing the protected dict out of the object is a bit nasty, # but we don't really want the overhead of copying the dict. - return obj._dict + try: + return obj._dict + except AttributeError: + # When the C implementation of frozendict is used, + # there isn't a `_dict` attribute with a dict + # so we resort to making a copy of the frozendict + return dict(obj) raise TypeError( "Object of type %s is not JSON serializable" % obj.__class__.__name__ )