adafruit / Adafruit_CircuitPython_Requests

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

https failure #99

Closed rodneygmorgan closed 1 year ago

rodneygmorgan commented 2 years ago

Running the requests_simpletest.py example on an AdaFruite MatrixPortal generates the following error(s) if the coinbase url is changed to https. You can query the url via https from a browser. Here is the output from the serial terminal.

code.py output:
ESP32 SPI webclient test
ESP32 found and in idle mode
Firmware vers. bytearray(b'1.2.2\x00')
MAC addr: ['0x4', '0x63', '0x43', '0xc2', '0x9d', '0x1c']
        PortMorgan              RSSI: -33
Connecting to AP...
Connected to PortMorgan         RSSI: -30
My IP address is 10.0.0.203
IP lookup adafruit.com: 104.20.38.240
Ping google.com: 40 ms
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
This is a test of Adafruit WiFi!
If you can read this, its working :)
----------------------------------------

Fetching json from https://api.coindesk.com/v1/bpi/currentprice/USD.json
Traceback (most recent call last):
  File "code.py", line 65, in <module>
  File "adafruit_requests.py", line 847, in get
  File "adafruit_requests.py", line 693, in request
  File "adafruit_requests.py", line 546, in _get_socket
RuntimeError: Sending request failed
`
=============================
I have confirmed this behavior with a stripped down version of AdaFruit's 'Moon Clock'.
=============================
`import board
import busio
from adafruit_matrixportal.network import Network
from adafruit_matrixportal.matrix import Matrix

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)
NETWORK.connect()
print("\nMatrixPortal IP address is", NETWORK.ip_address,"\n")

time_url = 'http://worldtimeapi.org/api/timezone/America/Denver'
print("Get the time from: ",time_url,"\n")
foo = NETWORK.fetch_data(time_url)
print(foo)

url = 'https://api.met.no/weatherapi/sunrise/2.0/.json?lat=30&lon=105&date=2022-01-22&offset=-07:00'
print("\nGet the moondata from: ",url,"\n")
foo = NETWORK.fetch_data(url)
print(foo)
anecdata commented 2 years ago

It could be a certificate issue. What version of NINA firmware is installed on your MatrixPortal? My PyPortal with 1.7.4 loads the HTTPS coindesk JSON.

EDIT: Looks like it's 1.2.2. There have been certificate updates since then. There's an update learn guide here: https://learn.adafruit.com/upgrading-esp32-firmware

anecdata commented 1 year ago

@rodneygmorgan I just tested this URL on a PyPortal, using Requests directly, with NINA v1.7.4 and it loaded fine. Closing. Please re-open if updating the NINA firmware doesn't solve it for you.