From 9f62a0d72aa72ac76ea8529dc9039dbc2263fedd Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 2 Jul 2026 15:39:11 +0200 Subject: [PATCH 1/3] add port back to host arguments (sends correct host-header, fixes redirects) --- adafruit_requests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_requests.py b/adafruit_requests.py index c21f69c..c86433a 100644 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -647,7 +647,7 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen ) ok = True try: - self._send_request(socket, host, method, path, headers, data, json, files) + self._send_request(socket, f"{host}:{port}", method, path, headers, data, json, files) except OSError as exc: last_exc = exc ok = False @@ -688,7 +688,7 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen url = redirect elif redirect[0] == "/": # relative URL, absolute path - url = "/".join([proto, dummy, host, redirect[1:]]) + url = "/".join([proto, dummy, f"{host}:{port}", redirect[1:]]) else: # relative URL, relative path path = path.rsplit("/", 1)[0] @@ -697,7 +697,7 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen path = path.rsplit("/", 1)[0] redirect = redirect.split("../", 1)[1] - url = "/".join([proto, dummy, host, path, redirect]) + url = "/".join([proto, dummy, f"{host}:{port}", path, redirect]) self._last_response = resp resp = self.request(method, url, data, json, headers, stream, timeout) From 5bf248c3fda2d5236a14e7cc71d4e609fd6a46f2 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 2 Jul 2026 16:01:38 +0200 Subject: [PATCH 2/3] fix formatting --- adafruit_requests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_requests.py b/adafruit_requests.py index c86433a..fbf0e4b 100644 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -647,7 +647,9 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen ) ok = True try: - self._send_request(socket, f"{host}:{port}", method, path, headers, data, json, files) + self._send_request( + socket, f"{host}:{port}", method, path, headers, data, json, files + ) except OSError as exc: last_exc = exc ok = False From 46b1afb26ab50bc1ea828b84fb984904218908cb Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 2 Jul 2026 20:32:41 +0200 Subject: [PATCH 3/3] fix code to make tests happy --- adafruit_requests.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_requests.py b/adafruit_requests.py index fbf0e4b..75b5a70 100644 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -620,8 +620,10 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen raise ValueError("Unsupported protocol: " + proto) if ":" in host: - host, port = host.split(":", 1) + host_only, port = host.split(":", 1) port = int(port) + else: + host_only = host if self._last_response: self._last_response.close() @@ -638,7 +640,7 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen while retry_count < 2: retry_count += 1 socket = self._connection_manager.get_socket( - host, + host_only, port, proto, session_id=self._session_id, @@ -647,9 +649,7 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen ) ok = True try: - self._send_request( - socket, f"{host}:{port}", method, path, headers, data, json, files - ) + self._send_request(socket, host, method, path, headers, data, json, files) except OSError as exc: last_exc = exc ok = False @@ -690,7 +690,7 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen url = redirect elif redirect[0] == "/": # relative URL, absolute path - url = "/".join([proto, dummy, f"{host}:{port}", redirect[1:]]) + url = "/".join([proto, dummy, host, redirect[1:]]) else: # relative URL, relative path path = path.rsplit("/", 1)[0] @@ -699,7 +699,7 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen path = path.rsplit("/", 1)[0] redirect = redirect.split("../", 1)[1] - url = "/".join([proto, dummy, f"{host}:{port}", path, redirect]) + url = "/".join([proto, dummy, host, path, redirect]) self._last_response = resp resp = self.request(method, url, data, json, headers, stream, timeout)