Skip to content

Commit

Permalink
Solve Datetime object not JSON serializable
Browse files Browse the repository at this point in the history
Simple fix using "default=" argument of json.dumps to pass a date_handler.
  • Loading branch information
konoufo committed Jan 25, 2015
1 parent ba9b2f6 commit ba56a56
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions parse_rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down

0 comments on commit ba56a56

Please sign in to comment.