diff --git a/parse_rest/connection.py b/parse_rest/connection.py index c0a3dd6..3d508f2 100644 --- a/parse_rest/connection.py +++ b/parse_rest/connection.py @@ -44,8 +44,9 @@ def ret(obj, *args, **kw): raise core.ParseError(message) func(obj, *args, **kw) return ret - - +# Using this as "default=" argument solve the problem with Datetime object not being JSON serializable +def date_handler(obj): + return obj.isoformat() if hasattr(obj, 'isoformat') else obj class ParseBase(object): ENDPOINT_ROOT = API_ROOT @@ -72,7 +73,7 @@ def execute(cls, uri, http_verb, extra_headers=None, batch=False, body=None, **k url = uri if uri.startswith(API_ROOT) else cls.ENDPOINT_ROOT + uri if body is None: - data = kw and json.dumps(kw) or "{}" + data = kw and json.dumps(kw, default=date_handler) or "{}" else: data = body if http_verb == 'GET' and data: