parkerhancock / patent_client

A collection of ORM-style clients to public patent data
Other
92 stars 35 forks source link

JSON Decode error when accessing EPO bibliographic data endpoint #76

Closed parkerhancock closed 1 year ago

parkerhancock commented 1 year ago

Investigate issue mentioned in #74 related to the Inpadoc endpoint

Example:

pub = Inpadoc.objects.get('EP3082535A1')
print(pub.biblio.title)

Error:


Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/requests/models.py", line 960, in json
    return complexjson.loads(self.content.decode(encoding), **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, 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/volk/patents_search/test.py", line 24, in <module>
    pub = Inpadoc.objects.get('EP3082535A1')
  File "/home/volk/.local/lib/python3.10/site-packages/patent_client/epo/ops/published/manager.py", line 47, in get
    result = PublishedApi.biblio.get_biblio(number, doc_type, format)
  File "/home/volk/.local/lib/python3.10/site-packages/patent_client/epo/ops/published/api.py", line 47, in get_biblio
    return cls.get_constituents(number, doc_type, format, constituents="biblio")
  File "/home/volk/.local/lib/python3.10/site-packages/patent_client/epo/ops/published/api.py", line 40, in get_constituents
    response = session.get(url)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
  File "/home/volk/.local/lib/python3.10/site-packages/patent_client/epo/ops/session.py", line 24, in request
    auth_response = self.get_token()
  File "/home/volk/.local/lib/python3.10/site-packages/patent_client/epo/ops/session.py", line 37, in get_token
    data = response.json()
  File "/usr/lib/python3.10/site-packages/requests/models.py", line 968, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
parkerhancock commented 1 year ago

The cause here is invalid EPO OPS credentials. Please refer to the documentation at https://patent-client.readthedocs.io/en/stable/getting_started.html for correct configuration.

I have also added a more informative OpsAuthenticationException that will show future users how to solve this problem if it reoccurs in #77