From df346e8703bcd279ceba524f0272f7d86c3586d1 Mon Sep 17 00:00:00 2001 From: SergioLangaritaBenitez Date: Thu, 18 Jun 2026 13:32:53 +0200 Subject: [PATCH 1/2] fix: add DELETE support and Content-Type header in make_request --- oscar_python/_utils.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/oscar_python/_utils.py b/oscar_python/_utils.py index 945d8c4..5f3a27b 100644 --- a/oscar_python/_utils.py +++ b/oscar_python/_utils.py @@ -15,6 +15,7 @@ import base64 import json import os +import time as _time import requests import liboidcagent as agent _DEFAULT_TIMEOUT = 60 @@ -32,21 +33,29 @@ def make_request(c, path, method, **kwargs): url = c.endpoint+path - if method in ["post", "put"]: - if "token" in kwargs.keys() and kwargs["token"]: - headers = get_headers_with_token(kwargs["token"]) - req_kwargs = {"headers": headers, "verify": c.ssl, "timeout": timeout} - if "data" in kwargs.keys() and kwargs["data"]: - req_kwargs["data"] = kwargs["data"] - result = requests.request(method, url, **req_kwargs) - else: - result = requests.request(method, url, headers=headers, verify=c.ssl, timeout=timeout) + max_retries = 3 + for attempt in range(max_retries): + if method in ["post", "put", "delete"]: + if "token" in kwargs.keys() and kwargs["token"]: + headers = get_headers_with_token(kwargs["token"]) + req_kwargs = {"headers": headers, "verify": c.ssl, "timeout": timeout} + if "data" in kwargs.keys() and kwargs["data"]: + req_kwargs["data"] = kwargs["data"] + req_kwargs["headers"]["Content-Type"] = "application/json" + result = requests.request(method, url, **req_kwargs) + else: + result = requests.request(method, url, headers=headers, verify=c.ssl, timeout=timeout) - if "handle" in kwargs.keys() and kwargs["handle"] is False: - return result + if "handle" in kwargs.keys() and kwargs["handle"] is False: + return result - result.raise_for_status() - return result + if result.status_code == 500 and method == "put": + if attempt < max_retries - 1: + _time.sleep(0.5 * (2 ** attempt)) + continue + + result.raise_for_status() + return result def get_headers(c): From 8a2c2e28d4e5a43efa8569a160bf19a3ee0dee43 Mon Sep 17 00:00:00 2001 From: SergioLangaritaBenitez Date: Thu, 18 Jun 2026 13:38:27 +0200 Subject: [PATCH 2/2] fix: update test_make_request_post to expect Content-Type header --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index dcc66dc..cb99af7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -78,7 +78,7 @@ class MockClient: assert response.status_code == 200 mock_request.assert_called_once_with( "post", "http://test.com/test", - headers={"Authorization": "Bearer test_token"}, + headers={"Authorization": "Bearer test_token", "Content-Type": "application/json"}, verify=True, data="test_data", timeout=60)