adafruit / Adafruit_CircuitPython_Requests

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

Simpletest does not work with HTTPS, ESP32SPI #57

Closed brentru closed 3 years ago

brentru commented 3 years ago

Changing the GET_URL from JSON_GET_URL = "http://httpbin.org/get" toJSON_GET_URL = "https://httpbin.org/get"` raises error:

Fetching JSON data from https://httpbin.org/get
Traceback (most recent call last):
  File "code.py", line 59, in <module>
  File "adafruit_requests.py", line 692, in get
  File "adafruit_requests.py", line 576, in request
  File "adafruit_requests.py", line 457, in _get_socket
  File "adafruit_requests.py", line 660, in wrap_socket
AttributeError: 'NoneType' object has no attribute 'TLS_MODE'

Request and ESP32SPI are on the latest versions Adafruit CircuitPython 6.1.0-beta.2 on 2020-12-03; Adafruit PyPortal with samd51j20

brentru commented 3 years ago

issue is in call of set_socket within the example. Lacks the required iface paramter: requests.set_socket(socket) to requests.set_socket(socket, esp)

After modification, both HTTP and HTTPs domains work as expected:

----------------------------------------
JSON Response:  {'url': 'https://httpbin.org/get', 'headers': {'User-Agent': 'Adafruit CircuitPython', 'Host': 'httpbin.org', 'X-Amzn-Trace-Id': 'Root=1-5feccee8-277a07403d46f4c14686b262'}, 'args': {}, 'origin': '108.12.192.159'}
----------------------------------------
POSTing data to https://httpbin.org/post: 31F
----------------------------------------
Data received from server: 31F
----------------------------------------
POSTing data to https://httpbin.org/post: {'Date': 'July 25, 2019'}
----------------------------------------
JSON Data received from server: {'Date': 'July 25, 2019'}
----------------------------------------

I'll put in a PR

brentru commented 3 years ago

Fixed by #58, merged and released.