open-meteo / python-requests

Open-Meteo Python Library using `requests`
MIT License
15 stars 4 forks source link

Unable to use POST method #74

Closed shin-tezuka closed 2 months ago

shin-tezuka commented 2 months ago

Hi,

Thank you for providing the great SDK.

I have tried to get weather data using a POST method like weather_api(URL, params=params, method="POST") according to this discussion.

But it raises the exception below.

requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type for url: https://archive-api.open-meteo.com/v1/archive...

My environments are as follows;

Python  3.11.6
requests 2.31.0
openmeteo_requests 1.2.0
requests-cache 1.2.1
retry-requests 2.0.0

Could you consider modifying the code like the one below to fix this problem?

--- openmeteo_requests/Client.py.orig
+++ openmeteo_requests/Client.py
@@ -24,7 +24,7 @@
     def _get(self, cls: type[T], url: str, params: any, method: str) -> list[T]:
         params["format"] = "flatbuffers"

-        response = self.session.request(method, url, params=params)
+        response = self.session.request(method, url, params=params, data=params)
         if response.status_code in [400, 429]:
             response_body = response.json()
             raise OpenMeteoRequestsError(response_body)

Regards,

patrick-zippenfenig commented 2 months ago

Thanks for the report. I fixed it in https://github.com/open-meteo/python-requests/commit/103c53cd79cfa2000bbb3b409e3ff435c2421dcc and released in https://github.com/open-meteo/python-requests/releases/tag/v1.2.1

shin-tezuka commented 2 months ago

@patrick-zippenfenig Thanks for the updates. It works perfectly for me.