Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError on SPARQLError #446

Closed
sirex opened this issue Dec 31, 2014 · 2 comments · Fixed by #599
Closed

UnicodeEncodeError on SPARQLError #446

sirex opened this issue Dec 31, 2014 · 2 comments · Fixed by #599
Labels
bug Something isn't working fix-in-progress SPARQL
Milestone

Comments

@sirex
Copy link

sirex commented Dec 31, 2014

Here is code sample how to reproduce this error:

import sys
import pprint
import rdflib

assert sys.version.startswith('2.7.6')
assert rdflib.__version__ == '4.0.1'

graph = rdflib.Graph()
graph.parse('http://dbpedia.org/resource/Metallica')
rows = graph.query('''
    SELECT DISTINCT ?p ?o
    WHERE {
        ?s ?p ?o .
        FILTER(lang(?o) = "" || lang(?o) = "en")
    }
''')

pprint.pprint(list(rows))

Running above, gives this:

Traceback (most recent call last):
  File "testme.py", line 18, in <module>
    pprint.pprint(list(rows))
  File "rdflib/query.py", line 238, in __len__
    return len(self.bindings)
  File "rdflib/query.py", line 178, in _get_bindings
    self._bindings += list(self._genbindings)
  File "rdflib/plugins/sparql/evaluate.py", line 353, in evalDistinct
    for x in res:
  File "rdflib/plugins/sparql/evaluate.py", line 362, in <genexpr>
    return (row.project(project.PV) for row in res)
  File "rdflib/plugins/sparql/evaluate.py", line 153, in evalFilter
    if _ebv(part.expr, c.forget(ctx)):
  File "rdflib/plugins/sparql/evalutils.py", line 50, in _ebv
    return EBV(expr.eval(ctx))
  File "rdflib/plugins/sparql/parserutils.py", line 194, in eval
    return self._evalfn(ctx)
  File "rdflib/plugins/sparql/operators.py", line 823, in ConditionalOrExpression
    expr = e.expr
  File "rdflib/plugins/sparql/parserutils.py", line 173, in __getattr__
    return self[a]
  File "rdflib/plugins/sparql/parserutils.py", line 163, in __getitem__
    return self._value(OrderedDict.__getitem__(self, a))
  File "rdflib/plugins/sparql/parserutils.py", line 158, in _value
    return value(self.ctx, val, variables)
  File "rdflib/plugins/sparql/parserutils.py", line 62, in value
    return val.eval(ctx)  # recurse?
  File "rdflib/plugins/sparql/parserutils.py", line 194, in eval
    return self._evalfn(ctx)
  File "rdflib/plugins/sparql/operators.py", line 783, in RelationalExpression
    raise SPARQLError('I cannot compare this non-node: %s' % expr)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 61-69: ordinal not in range(128)

I got same error on fresh master version.

@joernhees
Copy link
Member

verified on rdflib 4.1.2

@gromgull :
debugging tells me that expr actually is another SPARQLError exception instead of a node...

ipdb> expr
SPARQLError(u'Non-literal passed as string: http://ka.dbpedia.org/resource/\u10db\u10d4\u10e2\u10d0\u10da\u10d8\u10d9\u10d0',)

suspecting someone actually returns a SPARQLError rather than raising it i find https://github.com/RDFLib/rdflib/blob/master/rdflib/plugins/sparql/parserutils.py#L196 . It excepts a SPARQLError but then returns it... should it maybe re-raise it?

Another problem is that the UnicodeEncodeError actually comes from https://github.com/RDFLib/rdflib/blob/master/rdflib/plugins/sparql/operators.py#L783 or https://github.com/RDFLib/rdflib/blob/master/rdflib/plugins/sparql/operators.py#L881 ... thing is that "... %s .." % s is used in various places where u"... %s ..." % s should probably be used, no?

@sirex
Copy link
Author

sirex commented Jan 1, 2015

@joernhees joernhees added bug Something isn't working SPARQL labels Feb 19, 2015
@joernhees joernhees added this to the rdflib 4.2.1 milestone May 7, 2015
@joernhees joernhees modified the milestones: rdflib 4.2.1, rdflib 4.2.2 Aug 11, 2015
joernhees added a commit to joernhees/rdflib that referenced this issue Feb 16, 2016
joernhees added a commit to joernhees/rdflib that referenced this issue Feb 16, 2016
joernhees added a commit that referenced this issue Feb 27, 2016
fix unicode encoding errors in sparql processor, closes #446
colinfang pushed a commit to colinfang/rdflib that referenced this issue Apr 26, 2020
colinfang pushed a commit to colinfang/rdflib that referenced this issue Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix-in-progress SPARQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants