From e3b0de0aa217672161107b0bbf189e09474a4345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Fri, 10 Nov 2023 16:28:09 +0100 Subject: [PATCH] fix: add session cookies to all update queries (if needed) --- openfoodfacts/api.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/openfoodfacts/api.py b/openfoodfacts/api.py index 8f9ab0d..15848f1 100644 --- a/openfoodfacts/api.py +++ b/openfoodfacts/api.py @@ -26,14 +26,20 @@ def send_get_request( def send_for_urlencoded_post_request( url: str, body: Dict[str, Any], api_config: APIConfig ) -> requests.Response: + cookies = None if api_config.username and api_config.password: body["user_id"] = api_config.username body["password"] = api_config.password + elif api_config.session_cookie: + cookies = { + "session": api_config.session_cookie, + } r = http_session.post( url, data=body, timeout=api_config.timeout, auth=get_http_auth(api_config.environment), + cookies=cookies, ) r.raise_for_status() return r