Skip to content

Instantly share code, notes, and snippets.

@anecdata
Last active August 29, 2022 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anecdata/93ccb18e49d0d45f3c9eab3c6898d404 to your computer and use it in GitHub Desktop.
Save anecdata/93ccb18e49d0d45f3c9eab3c6898d404 to your computer and use it in GitHub Desktop.
Simple HTTPS request - CircuitPython on Espressif
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