Skip to content

Instantly share code, notes, and snippets.

@rtt
Created December 8, 2012 23:50
Show Gist options
  • Save rtt/4242581 to your computer and use it in GitHub Desktop.
Save rtt/4242581 to your computer and use it in GitHub Desktop.
()> app git:(master) ✗ ipython
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import datetime
In [2]: import json
In [3]: json.dumps({'now': datetime.datetime.now()})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-dbc125e49797> in <module>()
----> 1 json.dumps({'now': datetime.datetime.now()})
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.pyc in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, encoding, default, **kw)
229 cls is None and indent is None and separators is None and
230 encoding == 'utf-8' and default is None and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.pyc in encode(self, o)
199 # exceptions aren't as detailed. The list call should be roughly
200 # equivalent to the PySequence_Fast that ''.join() would do.
--> 201 chunks = self.iterencode(o, _one_shot=True)
202 if not isinstance(chunks, (list, tuple)):
203 chunks = list(chunks)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.pyc in iterencode(self, o, _one_shot)
262 self.key_separator, self.item_separator, self.sort_keys,
263 self.skipkeys, _one_shot)
--> 264 return _iterencode(o, 0)
265
266 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.pyc in default(self, o)
176
177 """
--> 178 raise TypeError(repr(o) + " is not JSON serializable")
179
180 def encode(self, o):
TypeError: datetime.datetime(2012, 12, 8, 23, 49, 23, 47250) is not JSON serializable
In [4]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment