Skip to content

SPARQL result parsing does not work with lxml #1847

@aucampia

Description

@aucampia

thanks for @edmondchuc for reporting this, this came up when he was working on integrating pyld in #1836 - pyld pulls in lxml and with lxml some tests fail that pass otherwise:

https://github.com/RDFLib/rdflib/runs/6061070121?check_suite_focus=true#step:11:674

  =========================== short test summary info ============================
  FAILED test/test_sparql/test_result.py::test_select_result_serialize_parse[xml-None-utf-8]
  FAILED test/test_sparql/test_result.py::test_select_result_serialize_parse[xml-TEXT_IO-utf-8]
  FAILED test/test_sparql/test_result.py::test_select_result_serialize_parse[xml-BINARY_IO-utf-8]
  FAILED test/test_sparql/test_result.py::test_select_result_serialize_parse[xml-STR_PATH-utf-8]
  FAILED test/test_sparql/test_result.py::test_select_result_parse_serialized[xml-TEXT_IO-utf-8]
  = 5 failed, 5115 passed, 2 skipped, 115 xfailed, 54 warnings in 129.80s (0:02:09) =

Exceptions all occur inside XMLResultParser.parse:

__________________________________________________________ test_select_result_serialize_parse[xml-BINARY_IO-utf-8] __________________________________________________________
Traceback (most recent call last):
  File "/home/iwana/sw/d/github.com/iafork/rdflib.cleanish/test/test_sparql/test_result.py", line 318, in test_select_result_serialize_parse
    check_serialized(format.name, select_result, serialized_data)
  File "/home/iwana/sw/d/github.com/iafork/rdflib.cleanish/test/test_sparql/test_result.py", line 110, in check_serialized
    parsed_result = Result.parse(StringIO(data), format=format)
  File "/home/iwana/sw/d/github.com/iafork/rdflib.cleanish/rdflib/query.py", line 215, in parse
    return parser.parse(source, content_type=content_type, **kwargs)
  File "/home/iwana/sw/d/github.com/iafork/rdflib.cleanish/rdflib/plugins/sparql/results/xmlresults.py", line 31, in parse
    return XMLResult(source)
  File "/home/iwana/sw/d/github.com/iafork/rdflib.cleanish/rdflib/plugins/sparql/results/xmlresults.py", line 40, in __init__
    tree = etree.parse(source, parser)
  File "src/lxml/etree.pyx", line 3536, in lxml.etree.parse
  File "src/lxml/parser.pxi", line 1893, in lxml.etree._parseDocument
  File "src/lxml/parser.pxi", line 1908, in lxml.etree._parseMemoryDocument
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions