From 81d146a82edacbe049287c65500ea0eadee187d2 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 29 Jul 2024 11:20:46 -0500 Subject: [PATCH 1/6] precommit copyright --- .pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ff19dde..f27b786 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,5 @@ -# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers # # SPDX-License-Identifier: Unlicense From 211e7cf9f60ce7b46416dc1fc5d3bb2075053788 Mon Sep 17 00:00:00 2001 From: aggieNick02 Date: Fri, 27 Sep 2024 14:53:58 -0500 Subject: [PATCH 2/6] Fix cases in Session.request method where an exception could lead to exiting the method without the created socket being owned by a response or closed. This would then cause future calls to get a socket with the same parameters to fail because one already existed and hadn't been closed. The PR https://github.com/adafruit/Adafruit_CircuitPython_Requests/pull/72 fixed this issue for one case where an exception could be raised. This generalizes that in an attempt to fix it in other cases that could still be hit. --- adafruit_requests.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/adafruit_requests.py b/adafruit_requests.py index f0c9e65..427b9e1 100644 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -622,6 +622,10 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen # We may fail to send the request if the socket we got is closed already. So, try a second # time in that case. + # Note that the loop below actually tries a second time in other failure cases too, + # namely timeout and no data from socket. This was not covered in the stated intent of the + # commit that introduced the loop, but removing the retry from those cases could prove + # problematic to callers that now depend on that resiliency. retry_count = 0 last_exc = None while retry_count < 2: @@ -643,17 +647,23 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen if ok: # Read the H of "HTTP/1.1" to make sure the socket is alive. send can appear to work # even when the socket is closed. - if hasattr(socket, "recv"): - result = socket.recv(1) - else: - result = bytearray(1) - try: + # Both recv/recv_into can raise OSError; when that happens, we need to call + # _connection_manager.close_socket(socket) or future calls to _connection_manager.get_socket() + # for the same parameter set will fail + try: + if hasattr(socket, "recv"): + result = socket.recv(1) + else: + result = bytearray(1) socket.recv_into(result) - except OSError: - pass - if result == b"H": - # Things seem to be ok so break with socket set. - break + if result == b"H": + # Things seem to be ok so break with socket set. + break + else: + raise RuntimeError("no data from socket") + except (OSError, RuntimeError) as exc: + last_exc = exc + pass self._connection_manager.close_socket(socket) socket = None From 4c9372bb32598eaf1427ba31f63b459b866fb946 Mon Sep 17 00:00:00 2001 From: aggieNick02 Date: Fri, 27 Sep 2024 14:59:58 -0500 Subject: [PATCH 3/6] fix line length in comment --- adafruit_requests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_requests.py b/adafruit_requests.py index 427b9e1..5bcf0e4 100644 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -648,8 +648,8 @@ def request( # noqa: PLR0912,PLR0913,PLR0915 Too many branches,Too many argumen # Read the H of "HTTP/1.1" to make sure the socket is alive. send can appear to work # even when the socket is closed. # Both recv/recv_into can raise OSError; when that happens, we need to call - # _connection_manager.close_socket(socket) or future calls to _connection_manager.get_socket() - # for the same parameter set will fail + # _connection_manager.close_socket(socket) or future calls to + # _connection_manager.get_socket() for the same parameter set will fail try: if hasattr(socket, "recv"): result = socket.recv(1) From b1741b3d617203fc3932ad5dab0f75c9e1daac67 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 4/6] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index f3a8700..689c1af 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -100,7 +100,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, From 5edee7367cd049c694e2d9c90989d09376055276 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 5/6] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: From bbb24801ecbf0e4453f809a15c851200fd4fb764 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 26 Feb 2025 14:52:15 -0500 Subject: [PATCH 6/6] update examples to use ap_info --- examples/esp32spi/requests_esp32spi_advanced.py | 2 +- examples/esp32spi/requests_esp32spi_simpletest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/esp32spi/requests_esp32spi_advanced.py b/examples/esp32spi/requests_esp32spi_advanced.py index 6754dbf..170589f 100644 --- a/examples/esp32spi/requests_esp32spi_advanced.py +++ b/examples/esp32spi/requests_esp32spi_advanced.py @@ -40,7 +40,7 @@ except RuntimeError as e: print("could not connect to AP, retrying: ", e) continue -print("Connected to", str(radio.ssid, "utf-8"), "\tRSSI:", radio.rssi) +print("Connected to", str(radio.ap_info.ssid, "utf-8"), "\tRSSI:", radio.ap_info.rssi) # Initialize a requests session pool = adafruit_connection_manager.get_radio_socketpool(radio) diff --git a/examples/esp32spi/requests_esp32spi_simpletest.py b/examples/esp32spi/requests_esp32spi_simpletest.py index 8a61209..3e856c0 100644 --- a/examples/esp32spi/requests_esp32spi_simpletest.py +++ b/examples/esp32spi/requests_esp32spi_simpletest.py @@ -40,7 +40,7 @@ except RuntimeError as e: print("could not connect to AP, retrying: ", e) continue -print("Connected to", str(radio.ssid, "utf-8"), "\tRSSI:", radio.rssi) +print("Connected to", str(radio.ap_info.ssid, "utf-8"), "\tRSSI:", radio.ap_info.rssi) # Initialize a requests session pool = adafruit_connection_manager.get_radio_socketpool(radio)