Comments (12)
notice that i don't have any intention to merge RDFLib/rdflib#550 as that would cut SPARQLWrapper to 1.7.1 instead of current 1.7.5, RDFLib/rdflib#550 and this issue is just to figure out where to fix this best (and quick)
from sparqlwrapper.
I think I found the problem.
Let's look at rdflib/plugins/stores/sparqlstore.py
from rdflib, line 414:
doc = ElementTree.parse(SPARQLWrapper.query(self).response)
This line exptects SPARQLWrapper.query(self).response
to be a file-like object in binary mode, i.e. yielding str, not unicode when calling read()
on it in Python 2. (As it is the body of an HTTP response, this is what I would expect too.) Adding the line
print repr(SPARQLWrapper.query(self).response.read())
right in front of it and running the unit tests again gives a unicode string as output:
u'<?xml version="1.0"?>\n<sparql xmlns="http://www.w3.org/2005/sparql-results#">\n <head>\n <variable name="o"/>\n </head>\n <results>\n <result>\n <binding name="o">\n <literal>1: adfk { \' \\" " { </literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>2: adfk } <foo> #\xe9\xef \\</literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>3: adfk { " \\\' \' { </literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>4: adfk } <foo> #\xe9\xef \\</literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>5: adfk { \' \\" " { </literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>6: adfk } <foo> #\xe9\xef \\</literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>7: ad adsfj 
 { 
 sadfj</literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>8: adfk { " \\\' \' { </literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>9: adfk } <foo> #\xe9\xef \\</literal>\n </binding>\n </result>\n <result>\n <binding name="o">\n <literal>10: ad adsfj 
 { 
 sadfj</literal>\n </binding>\n </result>\n </results>\n</sparql>\n'
Clearly, ElementTree
then tries to decode this as UTF-8, which causes Python to implicitely encode it as ASCII beforehand. Replacing line 414 with
doc = ElementTree.fromstring(SPARQLWrapper.query(self).response.read().encode('UTF-8'))
fixes the unit test. Of course, I wouldn't recomend this as workaround. I think that SPARQLWrapper should return a file-like object in binary mode. Could it be that the new keepalive package introduced in commit 609961a is at fault?
from sparqlwrapper.
It turns out it is. keepalive.py
provides a HTTPResponse
which derives from httplib.HTTPResponse
. It overrides the read function like this:
def read(self, amt=None):
...
s = self._rbuf + self._raw_read(amt).decode('UTF-8', 'ignore')
self._rbuf = ''
return s
from sparqlwrapper.
Reported this as an Issue against keepalive: wikier/keepalive#2
from sparqlwrapper.
@uholzer thanks for looking into this... can we just remove the .decode(...)
stuff? @wikier ?
from sparqlwrapper.
@joernhees I think what's causing troubles to @uholzer.... we'll discuss it in wikier/keepalive#2 and try to get a fix out asap. I'll keep you posted, guys.
from sparqlwrapper.
@joernhees wikier/keepalive#2 provides a candidate patch. Besides manual testing, I'd welcome a unit test on our side testing the reported issue; is that possible?
from sparqlwrapper.
see https://travis-ci.org/RDFLib/rdflib/builds/92929930 (was fixed on py2 but some stuff still fails on py3)
from sparqlwrapper.
a unit test inside SPARQLWrapper for queries/data with unicode chars would propbably be a good idea...
from sparqlwrapper.
@joernhees see wikier/keepalive#2, fixed in wikier/keepalive@b1d2c32.
Definitely a unit test it's necessary. If no one contributed it, by the end of the week I'll to find time to take care of it before pushing out a new 1.7.6
release depending on keepalive>=0.5
.
from sparqlwrapper.
any idea how this could be tested?
from sparqlwrapper.
OK, let's push this out for now.
from sparqlwrapper.
Related Issues (20)
- Next Release? HOT 20
- Introduce Lint tools
- Convert SPARQLWrapper.SmartWrapper to pandas dataframe HOT 6
- Removing https://rdflib.github.io/sparqlwrapper HOT 4
- Documentation format HOT 4
- using "describe" in a comment leads to error HOT 12
- Organize old PRs/Issues
- Make tests faster and more reliable.
- TLS changes in Python 3.10, insecure endpoint
- Allow earlier versions of rdflib HOT 2
- Test failures probably due to remote service issues
- Cannot install with conda for Python >=3.10 HOT 2
- QueryBadFormed: A bad request has been sent to the endpoint
- WikiData Not Returning CSV HOT 1
- Can't use SPARQLWrapper in nix-shell (somewhat OT)
- AWS Signature Version 4 Authentication Support HOT 2
- Align query result types with rdflib
- Unable to query the rdf:type HOT 3
- 405 (Method not allowed) for SELECT QUERY with # street address in comment HOT 2
- GraphDB 10.2.2: b'Missing parameter: query' on INSERT HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sparqlwrapper.