Python RDF库和SPARQL问题
在我的python文件中,我导入了rdflib,并实现了一些SPARQL查询来进行一些测试。这是我现在的代码Python RDF库和SPARQL问题,python,pycharm,sparql,rdf,rdfa,Python,Pycharm,Sparql,Rdf,Rdfa,在我的python文件中,我导入了rdflib,并实现了一些SPARQL查询来进行一些测试。这是我现在的代码 from rdflib import Graph if __name__ == '__main__': g = Graph() g.parse('http://localhost:8085/weather-2.html', format='rdfa') res1 = g.parse('http://localhost:8085/weather-2.html', fo
from rdflib import Graph
if __name__ == '__main__':
g = Graph()
g.parse('http://localhost:8085/weather-2.html', format='rdfa')
res1 = g.parse('http://localhost:8085/weather-2.html', format='rdfa')
print(res1.serialize(format='pretty-xml').decode("utf-8"))
print()
res2 = g.query("""SELECT ?obj
WHERE { <http://localhost:8085/weather-2.html> weather:region obj . }
""")
for row in res2:
print(row)
来自rdflib导入图
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
g=图()
g、 解析('http://localhost:8085/weather-2.html',format='rdfa')
res1=g.parse('http://localhost:8085/weather-2.html',format='rdfa')
打印(res1.serialize(format='pretty-xml')。解码(“utf-8”))
打印()
res2=g.query(“”选择?对象
其中{天气:地区obj.}
""")
对于res2中的行:
打印(行)
我运行了我的代码并得到了这个错误
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>
ConnectionRefusedError:[WinError 10061]无法建立连接,因为目标计算机主动拒绝它
在处理上述异常期间,发生了另一个异常:
urllib.error.urleror:
这是因为我的文件weather-2.html
的目录吗
或者我的记忆中缺少了什么
我使用pycharm作为我的编辑器,是的,我记得安装了所有的软件包,所以我不确定是什么导致了这个错误。是文件
http://localhost:8085/weather-2.html
在此URL下可用?天气前缀也未声明。我设法解决了连接错误,但现在我得到的天气前缀错误为u规定的。不确定为什么,因为我插入了“weather:region”,那么“Exception:Unknown namespace prefix:weather”是什么意思?我觉得这是一个简单的修复方法,但我不确定通过语法它看起来是什么样子。你能告诉我怎么做吗?我已经发布了关于这个问题的新问题。以下是链接:
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>