I'm using py2neo to export data from my neo4j database. (Using Python 2.7 on MacOS X)
Here's the code I've been using:
import csv
from py2neo import neo4j, cypher, node, rel
import pprint
ofile = open('mydata.csv', 'wb')
writer = csv.writer(ofile, delimiter='\t', quotechar='|', quoting = csv.QUOTE_ALL)
graph_db = neo4j.GraphDatabaseService("http://xx.xx.xx.xx:7474/db/data/")
qs = '''MATCH (a:MyLabel)
WHERE NOT a.shortdesc = ""
RETURN a.name, a.shortdesc, a.longdesc
ORDER BY a.name'''
query = neo4j.CypherQuery(graph_db, qs)
writer.writerows(query.stream())
In the properties a.shortdesc and a.longdesc there are clearly some strange characters, and I can't figure out how to encode them properly. I'm getting this error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 148: ordinal not in range(128)
I've been trying all sorts of different things... how can I take the namedtuples and properly encode them so I can write them to a csv file?