siku2 / hass-srf-weather

SRF Meteo forecasts for Home Assistant
MIT License
7 stars 3 forks source link

Accept expected response Content-Type "text/html" #8

Closed agners closed 2 years ago

agners commented 2 years ago

Computers are hard... :man_shrugging:

agners commented 2 years ago

Fixes: #7

agners commented 2 years ago

Ok, now I think I've got it right :smile:

It seems that newer aiohttp refuse to parse JSON if the MIME type isn't JSON. From what I understand, the API always returns (and did already in the past) text/html for weather forecasts, despite asking for application/json. IMHO that's wrong/weired, but it is what it is. For other requests or error cases, the API seems to return application/json. Make sure to check Content-Type depending on API used.

siku2 commented 2 years ago

It seems that newer aiohttp refuse to parse JSON if the MIME type isn't JSON.

I'm pretty sure this has been aiohttp's default behavior for quite some time. At least I remember struggling with this in the past :)

siku2 commented 2 years ago

Awesome, thanks a lot!