[英]An error in the sparql query when processing with Python
我正在使用 Python 處理 sparql 查詢。
def query(var):
query_with_placeholder="""
SELECT ?same_context as ?context str(?context_label) as ?context_label ?same_s as ?s str(?s_label) as ?s_label ?s_type ?p "$ENTITY_CODE$" as ?gene str(?text) as ?text
WHERE {
?transcript <http://purl.obolibrary.org/obo/SO_transcribed_from> <http://rdf.ebi.ac.uk/resource/ensembl/$ENTITY_CODE$> .
?transcript <http://purl.obolibrary.org/obo/SO_translates_to> ?ensembl_protein .
?reflect_protein owl:sameAs ?ensembl_protein
graph ?event {
?s ?p ?reflect_protein .
}.
{
?s a <http://lcsb.uni.lu/biokb#Chemical> .
?s owl:sameAs ?same_s .
?same_s rdfs:label ?s_label .
} UNION {
?s a <http://lcsb.uni.lu/biokb#Protein> .
?s owl:sameAs ?same_s .
?ensembl_transcript <http://purl.obolibrary.org/obo/SO_translates_to> ?same_s .
?ensembl_transcript rdfs:label ?s_label
}
?s a ?s_type .
?sentence <http://lcsb.uni.lu/biokb#hasEvent> ?event .
?sentence <http://lcsb.uni.lu/biokb#containsEntity> ?context .
?sentence <http://lcsb.uni.lu/biokb#text> ?text .
?context a <http://lcsb.uni.lu/biokb#Tissue> .
?context owl:sameAs ?same_context .
?same_context rdfs:label ?context_label .
}"""
new_query=query_with_placeholder.replace("$ENTITY_CODE$",var)
sparql = SPARQLWrapper("http://biokb.lcsb.uni.lu/sparql")
sparql.setQuery(new_query)
sparql.setReturnFormat(JSON)
result_of_query = sparql.query().convert()
return result_of_query
Var 是我正在迭代的列表中的一個元素。 由於使用此功能,我犯了一個錯誤
HTTPError: HTTP Error 404: File not found
和
EndPointNotFound: EndPointNotFound: it was impossible to connect with the endpoint in that address, check if it is correct.
Response:
b'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">\n<html>\n <head>\n <title>Error HTTP/1.1 404 File not found</title>\n </head>\n <body>\n <h3>Error HTTP/1.1 404 File not found</h3><pre>\nThe requested URL was not found URI = \'/sparql\'\n </pre></body></html>\n'
因此我的查詢在第 65 個元素處停止迭代。 但我仍然可以運行該元素和更多元素的查詢,所以我想它必須工作。
錯誤在哪里? 以及如何糾正?
當您在短時間內對DataBase 運行查詢過於頻繁時,就會出現此錯誤。
EndPointNotFound: EndPointNotFound: it was impossible to connect with the endpoint in that address, check if it is correct.
Response:
b'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">\n<html>\n <head>\n <title>Error HTTP/1.1 404 File not found</title>\n </head>\n <body>\n <h3>Error HTTP/1.1 404 File not found</h3><pre>\nThe requested URL was not found URI = \'/sparql\'\n </pre></body></html>\n'
將以下內容添加到 python 代碼中:
import time
time.sleep(2)
其中 2 - 以秒為單位的時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.