Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request milesrichardson#84 from konoufo/master
Browse files Browse the repository at this point in the history
Solve Datetime object not JSON serializable
  • Loading branch information
David Robinson committed Jan 30, 2015
2 parents 251b782 + ba56a56 commit 6e261e8
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 6e261e8

Please sign in to comment.