RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.15k stars 555 forks source link

Error when parsing turtle file #2790

Closed lymereJ closed 3 months ago

lymereJ commented 4 months ago

Using 0.7.0 running the following code gives me the following error. I've tried different version of Python, but I get the same error every time. It does seem to work on other machine so I'm not sure why it fails on mine. Any idea? The turtle file referenced below is here.

import rdflib
g = rdflib.Graph()
g.parse('./resources/brick/Brick.ttl')
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[4], [line 1](vscode-notebook-cell:?execution_count=4&line=1)
----> [1](vscode-notebook-cell:?execution_count=4&line=1) g.parse('./resources/brick/Brick.ttl', format="ttl")

File c:\Python310\lib\site-packages\rdflib\graph.py:1492, in Graph.parse(self, source, publicID, format, location, file, data, **args)
   [1489](file:///C:/Python310/lib/site-packages/rdflib/graph.py:1489) parser = plugin.get(format, Parser)()
   [1490](file:///C:/Python310/lib/site-packages/rdflib/graph.py:1490) try:
   [1491](file:///C:/Python310/lib/site-packages/rdflib/graph.py:1491)     # TODO FIXME: Parser.parse should have **kwargs argument.
-> [1492](file:///C:/Python310/lib/site-packages/rdflib/graph.py:1492)     parser.parse(source, self, **args)
   [1493](file:///C:/Python310/lib/site-packages/rdflib/graph.py:1493) except SyntaxError as se:
   [1494](file:///C:/Python310/lib/site-packages/rdflib/graph.py:1494)     if could_not_guess_format:

File c:\Python310\lib\site-packages\rdflib\plugins\parsers\notation3.py:2021, in TurtleParser.parse(self, source, graph, encoding, turtle)
   [2019](file:///C:/Python310/lib/site-packages/rdflib/plugins/parsers/notation3.py:2019) if not stream:
   [2020](file:///C:/Python310/lib/site-packages/rdflib/plugins/parsers/notation3.py:2020)     stream = source.getByteStream()
-> [2021](file:///C:/Python310/lib/site-packages/rdflib/plugins/parsers/notation3.py:2021) p.loadStream(stream)
   [2023](file:///C:/Python310/lib/site-packages/rdflib/plugins/parsers/notation3.py:2023) for prefix, namespace in p._bindings.items():
   [2024](file:///C:/Python310/lib/site-packages/rdflib/plugins/parsers/notation3.py:2024)     graph.bind(prefix, namespace)

File c:\Python310\lib\site-packages\rdflib\plugins\parsers\notation3.py:479, in SinkParser.loadStream(self, stream)
    [478](file:///C:/Python310/lib/site-packages/rdflib/plugins/parsers/notation3.py:478) def loadStream(self, stream: Union[IO[str], IO[bytes]]) -> Optional["Formula"]:
--> [479](file:///C:/Python310/lib/site-packages/rdflib/plugins/parsers/notation3.py:479)     return self.loadBuf(stream.read())

OSError: [Errno 22] Invalid argument
lu-pl commented 3 months ago

You are on a Windows machine and use a unix path.

lymereJ commented 3 months ago

@lu-pl - I get the same outcome if I run:

g.parse(".\\resources\\brick\\Brick.ttl")
lu-pl commented 3 months ago

Sorry I don't know anything about windows. Parsing the file works flawlessly on Linux.

Do you have read permissions for that file? Can you open it with open? You can also try passing a pathlib.Path to Graph.parse.

lymereJ commented 3 months ago

I do, but I think your suggestion is on the right track. I found that the file is backed-up by Microsoft's OneDrive, and when OneDrive is not running that file is not available. That's when I get the error, the error goes away when OneDrive is running!