Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve Datetime object not JSON serializable #84

Merged
merged 1 commit into from
Jan 30, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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