Comments (3)
Using requests
with the most logical config to request a SPARQL endpoint just works, so the problem is on SPARQLWrapper doing weird things internally:
import requests
from rdflib import Graph
query = """PREFIX up: <http://purl.uniprot.org/core/>
PREFIX taxon: <http://purl.uniprot.org/taxonomy/>
CONSTRUCT
{
?protein a up:HumanProtein .
}
WHERE
{
?protein a up:Protein .
?protein up:organism taxon:9606
} LIMIT 10"""
response = requests.post(
"https://sparql.uniprot.org/sparql/",
headers={
"Accept": "text/turtle"
},
data={
"query": query
},
timeout=60,
)
response.raise_for_status()
g = Graph()
g.parse(data=response.text, format="turtle")
print(response.text)
print(len(g))
In bonus we get basic features like timeout working! (the .setTimeout()
option from SPARQLWrapper does not work at all, at least for UniProt endpoint, but this should go in another issue)
from sparqlwrapper.
UniProt is not pure virtuoso and has some middleware that expects accept headers to ask for an rdf format if using describe and or construct.
from sparqlwrapper.
@JervenBolleman SPARQLWrapper also fails to run SELECT queries to SwissLipids https://beta.sparql.swisslipids.org/
Error 500 Internal Server Error</h1><p>The server was not able to handle your request.
:
from SPARQLWrapper import XML, SPARQLWrapper, JSON
query = """PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?comment ?query
WHERE
{
?sq a sh:SPARQLExecutable ;
rdfs:label|rdfs:comment ?comment ;
sh:select|sh:ask|sh:construct|sh:describe ?query .
}"""
sparql_endpoint = SPARQLWrapper("https://beta.sparql.swisslipids.org/")
sparql_endpoint.setReturnFormat(XML)
sparql_endpoint.setTimeout(60)
sparql_endpoint.setQuery(query)
results = sparql_endpoint.query().convert()
print(results)
With requests
it works:
import requests
query = """PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?comment ?query
WHERE
{
?sq a sh:SPARQLExecutable ;
rdfs:label|rdfs:comment ?comment ;
sh:select|sh:ask|sh:construct|sh:describe ?query .
}"""
response = requests.post(
"https://beta.sparql.swisslipids.org/",
headers={
"Accept": "application/json",
"User-agent": "sparqlwrapper 2.0.1a0 (rdflib.github.io/sparqlwrapper)"
},
data={
"query": query
},
timeout=60,
)
try:
response.raise_for_status()
print(response.json())
except requests.exceptions.HTTPError as e:
print(e)
print(response.text)
from sparqlwrapper.
Related Issues (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 2
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.