ossapi icon indicating copy to clipboard operation
ossapi copied to clipboard

Error decoding json response with `OssapiAsync`

Open cocoon333 opened this issue 1 year ago • 8 comments

image

Unfortunately, I cannot reproduce this error. It just happens once in a while when I am requesting user profiles.

cocoon333 avatar Apr 06 '23 22:04 cocoon333

The error generally occurs in clusters though, so possibly caused by network problems?

cocoon333 avatar Apr 06 '23 22:04 cocoon333

Most likely the osu! API being flaky returning errors in plaintext. Unsure if it's worth adding a mimetype check before decoding to JSON to avoid uncaught exceptions?

Stedoss avatar Apr 06 '23 23:04 Stedoss

I haven't seen this error before, which makes me think it's async-specific. On inspecting source code it seems that requests and aiohttp differ in how they handle json decoding: requests decodes regardless of mimetype (making appropriate guesses), and aiohttp throws by default.

It is possible the returned value here is a plaintext error, but it's also possible it's a normal json response with a differing mimetype. Even if this is an osu-web issue, I'd prefer to match sync behavior in all possible cases.

I've disabled throw-on-invalid-mimetype in cf56b0bd2e048027701da353d73dea347e15d405 in the hopes that fixes this. Please reopen if it doesn't.

tybug avatar Apr 06 '23 23:04 tybug

Unfortunately, the same error is still coming up.

cocoon333 avatar Apr 07 '23 09:04 cocoon333

Hmm. Was really hoping that would be the issue. I'd need to see the actual response to figure out what to do here. If you're hammering the api, it's possible you're hitting a ratelimit response that I've never seen before.

tybug avatar Apr 07 '23 18:04 tybug

Screenshot from 2023-04-08 17-13-41

Screenshot of more detailed error message

cocoon333 avatar Apr 09 '23 02:04 cocoon333

As an update, I hammered the api until I got a ratelimit error and can confirm it's returned as valid json:

...
  File "/Users/tybug/Desktop/Liam/coding/osu/ossapi/ossapi/ossapiv2_async.py", line 2428, in user
    return await self._get(User, f"/users/{user}/{mode.value if mode else ''}",
  File "/Users/tybug/Desktop/Liam/coding/osu/ossapi/ossapi/ossapiv2_async.py", line 637, in _get
    return await self._request(type_, "GET", url, params=params)
  File "/Users/tybug/Desktop/Liam/coding/osu/ossapi/ossapi/ossapiv2_async.py", line 624, in _request
    self._check_response(json_, url)
  File "/Users/tybug/Desktop/Liam/coding/osu/ossapi/ossapi/ossapiv2_async.py", line 633, in _check_response
    raise ValueError(f"api returned an error of `{json_['error']}` for "
ValueError: api returned an error of `Too Many Attempts.` for a request to https://osu.ppy.sh/api/v2/users/tybug2/

So that's not the culprit above.

tybug avatar Apr 26 '23 21:04 tybug