Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N-triples parser: reading a file fails without binary mode on Python 3.6 #1144

Closed
kouralex opened this issue Aug 17, 2020 · 2 comments · Fixed by #1145
Closed

N-triples parser: reading a file fails without binary mode on Python 3.6 #1144

kouralex opened this issue Aug 17, 2020 · 2 comments · Fixed by #1145

Comments

@kouralex
Copy link

Whilst trying to read an N-triples (.nt) file, I get this stack trace:

Traceback (most recent call last):
    Graph().parse(f, format='nt')
  File "[redacted]/.local/lib/python3.6/site-packages/rdflib/graph.py", line 1078, in parse
    parser.parse(source, self, **args)
  File "[redacted]/.local/lib/python3.6/site-packages/rdflib/plugins/parsers/nt.py", line 26, in parse
    parser.parse(f)
  File "[redacted]/.local/lib/python3.6/site-packages/rdflib/plugins/parsers/ntriples.py", line 150, in parse
    self.line = self.readline()
  File "[redacted]/.local/lib/python3.6/site-packages/rdflib/plugins/parsers/ntriples.py", line 173, in readline
    buffer = self.file.read(bufsiz)
  File "/usr/lib/python3.6/codecs.py", line 499, in read
    data = self.bytebuffer + newdata
TypeError: can't concat str to bytes

where f = open(file, 'r').

RDFLib Version: 5.0.0

It seems to be working on Python 2.7 as is, OR on Python 3.6 by adding the rb mode to the open(), however, that is not required for xml nor n3 format values. One can, of course, use the n3 option for .nt files but that will probably cause a small overhead.

@ashleysommer
Copy link
Contributor

@kouralex
Thanks for the bug report.
I think in this case most people probably either open with 'rb' as you suggested, or use the n3 parser, as you mentioned. Both of these are not ideal solutions, and we definitely need to get the ntriples parser updated to work properly in Python 3.6.

@ashleysommer
Copy link
Contributor

This should be fixed by #1145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants