python 3.9 and rdflib keep changing slashes in a url

Viewed 212

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

2 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.

The issue seems to be related to how your Python is set up.

On Mac and Windows I can just:

  • install Python 3.9 (or 3.8, 3.7 or 3.6)
  • install rdflib 6.0.0
    • C:\Users\nick\AppData\Local\Programs\Python\Python39\python.exe -m pip install rdflib
  • run the script using Python with rdflib now installed
    • C:\Users\nick\AppData\Local\Programs\Python\Python39\python.exe rdftest.py

This works fine on up-to-date Windows 10 on both the Command Prompt and on Powershell.

So this issues seems to be to do with your Python installation or Windows configuration, not rdflib per se.

Related