leonhard-s / auraxium

A high-level Python wrapper for the PlanetSide 2 API.
https://auraxium.readthedocs.io/
MIT License
28 stars 8 forks source link

ClientResponseError: 400, message='Bad Request' when querying census API #64

Closed yakMM closed 1 year ago

yakMM commented 1 year ago

Hello, I'm recently getting an error when querying the census API with auraxium.

I don't know if the problem is coming from an API change on Daybreak side or a recent change in the auraxium module.

The problem is fixed if I cast the url to str (using str(url) instead of url) here: https://github.com/leonhard-s/auraxium/blob/8fd4fa9eaa77ecd3b4cba571c285a4776aeaa119/auraxium/_rest.py#L484

Does the problem come from using yarl.URL object directly?

yakMM commented 1 year ago

I can reproduce the problem with the README example:

import asyncio
import auraxium
from auraxium import ps2

async def main():
    async with auraxium.Client() as client:
        char = await client.get_by_name(ps2.Character, 'auroram')
        print(char.name)
        print(char.data.prestige_level)

asyncio.run(main())

Gives:

auraxium.errors.ResponseError: An HTTP exception occurred

Fixed by casting the url as explained above.

leonhard-s commented 1 year ago

Hi, thank you for the report. I have been observing similar issues in the CI runs for https://github.com/leonhard-s/ps2-api-backup but was unable to reproduce it locally.

I will do some digging to see what caused this; there have been no changes to Auraxium lately. Either a new version of yarl changed a behaviour, or it was an API change.

leonhard-s commented 1 year ago

The error appears to have been an upstream issue related to a regression in yarl==1.9.1 or one of its dependencies. Version 1.9.2 of yarl no longer breaks requests.

I do not immediately see a connection to the only regression they mention in the release notes (https://github.com/aio-libs/yarl/issues/854), but I have not had time to investigate it in detail. Especially the explicit cast to str fixing the issue is quite interesting.

@yakMM please let me know if the issue is fixed for you after updating to yarl 1.9.2.

yakMM commented 1 year ago

The issue is indeed resolved with yarl 1.9.2, thanks.

Didn't really look in details, plus I don't really know about yarl, but the issue you are linking resembles very much the weird behavior I was experimenting.

This comment for example matches: https://github.com/aio-libs/yarl/issues/854#issuecomment-1521213518