Last active
August 29, 2022 04:28
-
-
Save anecdata/93ccb18e49d0d45f3c9eab3c6898d404 to your computer and use it in GitHub Desktop.
Simple HTTPS request - CircuitPython on Espressif
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wifi | |
import socketpool | |
import ssl | |
import adafruit_requests | |
# local | |
from secrets import secrets | |
URL = "https://example.com" | |
wifi.radio.connect(secrets['ssid'], secrets['password']) | |
pool = socketpool.SocketPool(wifi.radio) | |
context = ssl.create_default_context() | |
# context.check_hostname = False # can change dynamically (per-URL) | |
# context.load_verify_locations(cadata=CA_STRING) # custom certificate | |
requests = adafruit_requests.Session(pool, context) | |
with requests.get(URL) as response: | |
print(response.status_code, response.reason, response.headers) | |
print(response.content) # or response.text or response.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment