user1491915
user1491915

Reputation: 1085

py2neo - UnicodeEncodeError in query

I'm getting am error when querying neo4j using py2neo, and cant seem to solve it. My code:

data, metadata = cypher.execute(self._db, 'START s=node:pages(title="%s") MATCH (s)-[r]->(n) RETURN n.title' % topic)

And the error

  File "/usr/local/lib/python2.7/dist-packages/py2neo/cypher.py", line 50, in execute
    results = query.execute(**params or {})
  File "/usr/local/lib/python2.7/dist-packages/py2neo/neo4j.py", line 1011, in execute
    return CypherResults(self._execute(**params))
  File "/usr/local/lib/python2.7/dist-packages/py2neo/neo4j.py", line 1053, in __init__
    self._data = [record(*_hydrated(row)) for row in content["data"]]
  File "/usr/local/lib/python2.7/dist-packages/py2neo/neo4j.py", line 178, in _hydrated
    return type(data)([_hydrated(datum) for datum in data])
  File "/usr/local/lib/python2.7/dist-packages/py2neo/neo4j.py", line 177, in _hydrated
    elif is_collection(data):
  File "/usr/local/lib/python2.7/dist-packages/py2neo/util.py", line 134, in is_collection
    hasattr(None, obj)
None: 'ascii' codec can't encode character u'\xeb' in position 5: ordinal not in range(128)

Any clues?

Thank you

Upvotes: 0

Views: 564

Answers (2)

Nigel Small
Nigel Small

Reputation: 4495

This looks like it might be a bug in py2neo triggered by an unexpected byte sequence or character set in the query result data. Are you able to elaborate on the data you would expect this to return and whether you are using UTF-8?

Upvotes: 1

mrshanahan
mrshanahan

Reputation: 68

I would say that there's a non-ASCII byte in topic, and that's probably what's causing it. If you're having that issue, you could probably try

data, metadata = cypher.execute(self._db, u'START s=node:pages(title="%s") MATCH (s)-[r]->(n) RETURN n.title' % topic)

And that might actually solve your problem. (I'd just comment with this, but I can't, sorry.) If that doesn't work, try:

(u'STATE s=node:...' ... % topic.decode('utf-8')).encode('utf-8')

That would do it.

Upvotes: 0

Related Questions