create_node() failing with "not JSON serializable"

76 views
Skip to first unread message

Alan Robertson

unread,
Jul 24, 2012, 6:55:58 PM7/24/12
to Neo4J, Nigel Small
Hi,

I'm using py2neo, and am creating a node with an attribute that's an array of strings, and get the "not JSON serializable" error mentioned in the subject line.

Here's the attribute table I'm passing create_node():

Attribute table: {'exe': '/usr/local/zenoss/python/bin/.python.bin', 'nodetype': 'ipproc', 'uid': 'zenoss', 'cmdline': ['/usr/local/zenoss/python/bin/.python.bin', '/usr/local/zenoss/python/bin/runzope', '-C', '/usr/local/zenoss/zenoss/etc/zope.conf'], 'gid': 'zenoss', 'cwd': '/usr/local/zenoss/zenoss', 'name': '.python.bin'}

And below is the traceback - which complains about one of the string values.  It worked until I added the 'cmdline' element with an array-of-strings value.  So, I suspect that of being the issue.  It looks to me like I constructed them properly...  I've pulled out the cmdline value below to highlight it...

'cmdline': ['/usr/local/zenoss/python/bin/.python.bin',
            '/usr/local/zenoss/python/bin/runzope',
            '-C',
            '/usr/local/zenoss/zenoss/etc/zope.conf']


The attribute table was printed this way:
            print 'Attribute table: %s' % str(table)


Traceback follows...

Traceback (most recent call last):
  File "cma/newcma.py", line 1034, in <module>
    listener.listen()
  File "cma/newcma.py", line 993, in listen
    self.dispatcher.dispatch(fromaddr, frameset)
  File "cma/newcma.py", line 955, in dispatch
    self.dispatchtable[fstype].dispatch(origaddr, frameset)
  File "cma/newcma.py", line 940, in dispatch
    drone.logjson(json)
  File "cma/newcma.py", line 583, in logjson
    DroneInfo._JSONprocessors[dtype](self, jsonobj)
  File "cma/newcma.py", line 655, in add_tcplisteners
    CMAdb.cdb.new_ipproc(listenname, listenerinfo)
  File "cma/newcma.py", line 298, in new_ipproc
    ipproc = self.node_new(CMAdb.NODE_ipproc, name, unique=False, **table)
  File "cma/newcma.py", line 224, in node_new
    obj = self.db.create_node(tbl)
  File "/usr/local/lib/python2.7/dist-packages/py2neo/neo4j.py", line 233, in create_node
    result = self._post(self._lookup('node'), properties)
  File "/usr/local/lib/python2.7/dist-packages/py2neo/rest.py", line 252, in _post
    return self._request('POST', uri, json.dumps(data), **kwargs)
  File "/usr/lib/python2.7/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 201, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 264, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 178, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: '/usr/local/zenoss/python/bin/.python.bin' is not JSON serializable
Exception TypeError: "'NoneType' object is not callable" in <bound method HTTPClient.__del__ of <tornado.httpclient.HTTPClient object at 0x9d21dac>> ignored

-- 
    Alan Robertson <al...@unix.sh> - @OSSAlanR

"Openness is the foundation and preservative of friendship...  Let me claim from you at all times your undisguised opinions." - William Wilberforce

Nigel Small

unread,
Jul 25, 2012, 5:12:49 AM7/25/12
to Alan Robertson, Neo4J
Hi Alan

I'm currently on holiday until the end of next week but if you can raise a GitHub issue with this info, I can have a look after I get back.

Cheers
Nige
Reply all
Reply to author
Forward
0 new messages