tybug / ossapi

The definitive python wrapper for the osu! api.
https://tybug.github.io/ossapi/
GNU Affero General Public License v3.0
82 stars 18 forks source link

Error decoding json response with `OssapiAsync` #60

Open cocoon333 opened 1 year ago

cocoon333 commented 1 year ago

image

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

cocoon333 commented 1 year ago

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

Stedoss commented 1 year ago

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?

tybug commented 1 year ago

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.

cocoon333 commented 1 year ago

Unfortunately, the same error is still coming up.

tybug commented 1 year ago

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.

cocoon333 commented 1 year ago

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

Screenshot of more detailed error message

tybug commented 1 year ago

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.