gjhiggins/rdflib — Issue #150: problem with unicode literals in rdflib.compare.graph_diff
Author: gjhiggins
Created: 2011-10-19 01:31:08+00:00
State: open

Originally filed by pierre.a...@gmail.com on 2010-11-16T16:55:02

What steps will reproduce the problem?

from rdflib import Graph
from rdflib.compare import graph_diff
g1 = Graph()
g1.load("http://champin.net/foaf.rdf")
diff = graph_diff(g1, g1)

raises:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)

What is the expected output? What do you see instead?

should not raise an exception...

What version of the product are you using? On what operating system?

rdflib 3.0.0 on Linux, python 2.6.6

Please provide any additional information below.

line 219 of rdflib/compare.py should be
h.update(unicode(i).encode("utf8"))
this fixes the problem.

On the other hand, the fix above works with python 2.x, but would probably not work in python 3.x, while the original code probably works.

I don't know what is the best way to make the code compliant with both python 2 and 3, nor if this is relevant for rdflib.