4

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

codebot
  • 517
  • 8
  • 29
  • 55

2 Answers2

2

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.

Roxy
  • 1,015
  • 7
  • 20
Shpinks
  • 21
  • 4
  • 1
    Thanks for the potential root cause analysis here! If this really is the issue, it can indeed be solved with a PR to the RDFlib code (https://github.com/RDFLib/rdflib), however is this really the issue? When I use 6.0.0 on Windows (in testing my answer below) I didn't see the error. so if it really was this issue, inside RDFlib, wouldn't I have also see it? Can anyone else on Windows reproduce this error? – Nicholas Car Sep 05 '21 at 08:57
  • 1
    Hmmm... looks like I have to test some more on Windows... – Nicholas Car Sep 10 '21 at 07:05
0

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.

Nicholas Car
  • 1,164
  • 4
  • 7
  • Ok thanks. Do you have ay advise on how to solve the issue with just Python then? – codebot Sep 02 '21 at 10:31
  • Not really, because I can't replicate your error! – Nicholas Car Sep 03 '21 at 05:27
  • Why don't you run the second RDFlib example, https://rdflib.readthedocs.io/en/stable/gettingstarted.html#a-more-extensive-example? That script doesn't call out to the internet for data: it generates what it needs, so you might be able to run that to check that Python and RDFlib is working for you in general and it's only this web call thing that's a problem. – Nicholas Car Sep 03 '21 at 05:34