rhgrant10/berserk

JSONDecodeError in get_rating_history

mykter opened this issue · 5 comments

  • berserk version: 0.8.0
  • Python version: 3.8
  • Operating System: Linux

Description

When retrieving the rating history for a user, which works for many users, hit the following error. You can reproduce with user IDs A23012011 and AboodSalah.

What I Did

    history = client.users.get_rating_history(user)
  File "/home/mike/.local/lib/python3.8/site-packages/berserk/clients.py", line 298, in get_rating_history
    return self._r.get(path, converter=models.RatingHistory.convert)
  File "/home/mike/.local/lib/python3.8/site-packages/berserk/session.py", line 60, in get
    return self.request('GET', *args, **kwargs)
  File "/home/mike/.local/lib/python3.8/site-packages/berserk/session.py", line 56, in request
    return fmt.handle(response, is_stream=is_stream, converter=converter)
  File "/home/mike/.local/lib/python3.8/site-packages/berserk/formats.py", line 35, in handle
    return converter(self.parse(response))
  File "/home/mike/.local/lib/python3.8/site-packages/berserk/formats.py", line 76, in parse
    return response.json(cls=self.decoder)
  File "/home/mike/.local/lib/python3.8/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.8/json/__init__.py", line 370, in loads
    return cls(**kw).decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/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)

Thanks for reporting this. I'll make some time to investigate it this weekend.

I looked into this and it turns out the API returns an empty response body if there is no rating history for the user. I'll reach out to the lichess devs to make sure this is intentional and then also handle that situation more gracefully than an obtuse exception.

They agreed it was a bug. Should be fixed in production soon since it just got committed: lichess-org/lila@bea1b52.

Nice!

Closing this as fixed!

$ curl -s -H "Accept: application/json" \
          -H "Authorization: Bearer $LICHESS_TOKEN" \
          https://lichess.org/api/user/AboodSalah/rating-history
[]