Skip to content

Conversation

relic-se
Copy link
Contributor

If a device hasn't been configured properly either with CIRCUITPY_WIFI_SSID and CIRCUITPY_WIFI_PASSWORD or the "networks" setting, adafruit_portalbase.network.NetworkBase.connect will result in an obscure TypeError from the adafruit_esp32spi library.

This update filters the adafruit_portalbase.network.NetworkBase._wifi_credentials list to ensure that it includes valid ssid/password pairs. If no valid credentials are available, it will trigger an OSError exception with a descriptive message.

I am testing using the following program written for the Adafruit Fruit Jam with the adafruit_fruitjam library. The device has no WiFi credentials configured.

from adafruit_fruitjam import FruitJam
fruitjam = FruitJam(url="https://www.adafruit.com")
fruitjam.fetch()

Here is the REPL output before this update:

Connecting to AP None
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "adafruit_fruitjam/__init__.py", line 302, in fetch
  File "adafruit_portalbase/network.py", line 552, in fetch
  File "adafruit_portalbase/network.py", line 406, in connect
  File "adafruit_portalbase/wifi_coprocessor.py", line 85, in connect
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 657, in connect
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 680, in connect_AP
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 548, in wifi_set_network
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 421, in _send_command_get_response
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 303, in _send_command
TypeError: object of type 'NoneType' has no len()

Here's the REPL output after this update:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "adafruit_fruitjam/__init__.py", line 302, in fetch
  File "/lib/adafruit_portalbase/network.py", line 560, in fetch
  File "/lib/adafruit_portalbase/network.py", line 395, in connect
OSError: No wifi credentials provided

Note: I felt that OSError was appropriate for this exception because it is related to the device configuration before a request is made, but ConnectionError may follow the relative CPython implementation more closely.

Co-authored-by: foamyguy <foamyguy@gmail.com>
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thanks for working on it!

@FoamyGuy FoamyGuy merged commit d5c51a1 into adafruit:main Oct 3, 2025
1 check passed
adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants