Skip to content

content type mismatch #68

@vrvei

Description

@vrvei

when trying to get forecast for a given location, I always get a RequestError exception with status=200, reason=OK

I've done a bit of debugging...

  • Client.get() returns a Forecast initialized with await resp.json() as first parameter, without any inner parameters;
  • ClientResponse.json() expects 3 parameters, the last one being content_type: Optional[str] = "application/json" hence the method is being called with the default value application/json for the expected content type
  • however, inside the async def json I noticed that self.headers.get(hdrs.CONTENT_TYPE, "").lower() equals to application/text , yet the body seems to contain a valid json structure... b'{\n "current_condition": [\n {\n "FeelsLikeC": "4",\n "FeelsLikeF": "38",\n "cloudcover": "0",\n ... "mintempF": "46",\n "sunHour": "10.5",\n "totalSnow_cm": "0.0",\n "uvIndex": "5"\n }\n ]\n}'
  • therefore a ContentTypeError(ClientResponseError) is raised,
  • after a few failed attempts, Client.get() converts such "response exception" to a RequestError

it seems that:

  • there are problems with the validation of the content-type in the response, and this causes python-weather to fail to produce weather data
  • what starts out as a "response error" is converted into a "request error", and investigating a bit it actually seems more like a "response error"
  • also the description of the error tends to be quite confusing since it says status=200, reason=OK

context info:

  • python 3.12
  • python-weather 2.1.2
  • dependency aiohttp 3.13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions