pyld
pyld copied to clipboard
Exception raised with README.rst example
The jsonld.compact() example in README.rst raises an exception during json decoding.
If this example was intended to be a template for how to call compact() (i.e., not a working example), then perhaps clarification is warranted. (I'm new to json-ld and pyld, so I didn't know what to expect.)
Reproduction below:
snafu$ python3 -m venv pyld
snafu$ source pyld/bin/activate
(pyld) snafu$ python --version
Python 3.6.7
(pyld) snafu$ pip install pyld[requests]
[...]
Successfully installed pyld-1.0.4
(pyld) snafu$ pip freeze
certifi==2018.11.29
chardet==3.0.4
idna==2.8
pkg-resources==0.0.0
PyLD==1.0.4
requests==2.21.0
urllib3==1.24.1
(pyld) snafu$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyld import jsonld
>>> jsonld.compact('https://example.org/doc', 'https://example.org/context')
Traceback (most recent call last):
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/documentloader/requests.py", line 68, in loader
'document': response.json()
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/jsonld.py", line 677, in compact
expanded = self.expand(input_, options)
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/jsonld.py", line 775, in expand
remote_doc = options['documentLoader'](input_)
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/documentloader/requests.py", line 92, in loader
cause=cause)
pyld.jsonld.JsonLdError: ('Could not retrieve a JSON-LD document from the URL.',)
Type: jsonld.LoadDocumentError
Code: loading document failed
Cause: Expecting value: line 1 column 1 (char 0) File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/documentloader/requests.py", line 68, in loader
'document': response.json()
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/jsonld.py", line 145, in compact
return JsonLdProcessor().compact(input_, ctx, options)
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/jsonld.py", line 681, in compact
'jsonld.CompactError', cause=cause)
pyld.jsonld.JsonLdError: ('Could not expand input before compaction.',)
Type: jsonld.CompactError
Cause: ('Could not retrieve a JSON-LD document from the URL.',)
Type: jsonld.LoadDocumentError
Code: loading document failed
Cause: Expecting value: line 1 column 1 (char 0) File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/documentloader/requests.py", line 68, in loader
'document': response.json()
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/jsonld.py", line 677, in compact
expanded = self.expand(input_, options)
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/jsonld.py", line 775, in expand
remote_doc = options['documentLoader'](input_)
File "/home/reece/projects/biocommons/pyld/lib/python3.6/site-packages/pyld/documentloader/requests.py", line 92, in loader
cause=cause)
>>>