Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python 3.9 and rdflib keep changing slashes in a url

I am completely new in Python . I am using 3.9.2 and rdflib . I try to execute the first example,

from rdflib import Graph
g = Graph()
g.parse('http://dbpedia.org/resource/Semantic_Web')

for s, p, o in g:
    print(s, p, o)

I create a py file , paste it in and then using windows 10 cmd, I cd to my pyhton file and do python rdftest.py.

No matter how I set the url, I get

Traceback (most recent call last):
  File "D:\BACKUP\programming\rdftrest.py", line 3, in <module>
    g.parse('http://dbpedia.org/resource/Semantic_Web')
  File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\site-packages\rdflib\graph.py", line 1188, in parse
    source = create_input_source(
  File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\site-packages\rdflib\parser.py", line 281, in create_input_source
    ) = _create_input_source_from_location(
  File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\site-packages\rdflib\parser.py", line 312, in _create_input_source_from_location
    if path.exists():
  File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1407, in exists
    self.stat()
  File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1221, in stat
    return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is 
incorrect: 'http:\\dbpedia.org\\resource\\Semantic_Web' 

How can I fix that? Thank you

like image 631
codebot Avatar asked Sep 08 '25 06:09

codebot


1 Answers

It seems to be a bug in rdflib version 6.0.0. I confronted the same problem and the solution was to downgrade the version to 5.0.0. Then it seems to work fine.

Looks like the parse() function is messed up: it uses pathlib when it sees URL and urllib when it sees the file path.

like image 113
Shpinks Avatar answered Sep 10 '25 10:09

Shpinks