adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 36 forks source link

BrokenPipeError in network.fetch #127

Open dyeazel opened 1 year ago

dyeazel commented 1 year ago

I'm getting an error with network.fetch on an Adafruit Matrix Portal M4.

Error details:

Traceback (most recent call last):
  File "adafruit_requests.py", line 527, in _get_socket
  File "adafruit_requests.py", line 757, in connect
  File "adafruit_esp32spi/adafruit_esp32spi_socket.py", line 75, in connect
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 806, in socket_connect
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 702, in socket_open
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 332, in _send_command_get_response
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 302, in _wait_response_cmd
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 284, in _check_data
BrokenPipeError: Expected 01 but got 00

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "code.py", line 29, in <module>
  File "adafruit_portalbase/network.py", line 518, in fetch
  File "adafruit_requests.py", line 816, in get
  File "adafruit_requests.py", line 661, in request
  File "adafruit_requests.py", line 508, in _get_socket
RuntimeError: Sending request failed

sample code:

import board
import terminalio
from adafruit_matrixportal.network import Network

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

network = Network(status_neopixel=board.NEOPIXEL, debug=False)

if not network.is_connected:
    # connect to the network defined in secrets.py
    print("connecting")
    network.connect()

    # connect to a test page to show the network is working
    print("fetch test")
    response = network.fetch_data("https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400")
    print("")
    print("-" * 40)
    print(response)
    print("-" * 40)

# connect to another page that fails
print("fetch zones")
response = network.fetch("https://www.yeazel2.net/")
print()
print("-" * 40)
print(response)
print("-" * 40)

if you try the URL ( https://www.yeazel2.net/ ) in a browser you'll see that it works.

alienryes commented 3 months ago

I have the same issue with very similar code but a different API url: https://opensky-network.org/api/states/all?lamin=-2.0609&lomin=51.4238&lamax=-1.9510&lomax=51.4580

Retrieving data...Traceback (most recent call last): File "adafruit_connection_manager.py", line 271, in get_socket File "adafruit_connection_manager.py", line 63, in connect File "adafruit_esp32spi/adafruit_esp32spi_socket.py", line 77, in connect File "adafruit_esp32spi/adafruit_esp32spi.py", line 819, in socket_connect File "adafruit_esp32spi/adafruit_esp32spi.py", line 715, in socket_open File "adafruit_esp32spi/adafruit_esp32spi.py", line 341, in _send_command_get_response File "adafruit_esp32spi/adafruit_esp32spi.py", line 311, in _wait_response_cmd File "adafruit_esp32spi/adafruit_esp32spi.py", line 293, in _check_data BrokenPipeError: Expected 01 but got 00

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "code.py", line 26, in File "adafruit_portalbase/network.py", line 645, in fetch_data File "adafruit_portalbase/network.py", line 563, in fetch File "adafruit_requests.py", line 591, in get File "adafruit_requests.py", line 525, in request File "adafruit_connection_manager.py", line 282, in get_socket RuntimeError: Error connecting socket: Expected 01 but got 00

feduks commented 1 month ago

Both are using Let's Encrypt, and me too. I' am checking how to add this CA validate or ignore SSL verification. Keep in touch!

anecdata commented 1 month ago

You may need to update the NINA firmware on the ESP32 for an updated certificate bundle: https://learn.adafruit.com/upgrading-esp32-firmware/overview

feduks commented 1 month ago

Thanks @anecdata !!! First Upload Passthrough Code and after Download NINA Firmware. It´s important the first step.

dhalbert commented 1 month ago

Yes, updated NINA-FW has new root certificates: https://github.com/adafruit/nina-fw/pull/57. Note that there is still a problem with at least some elliptical cryptography cert chains: https://github.com/adafruit/nina-fw/issues/58