Closed
Description
I'm not sure whether this is an error in the examples or in the revised legacy API.
examples/requests_simpletest.py
and examples/requests_advanced.py
both contain code:
# Initialize a requests object with a socket and esp32spi interface
socket.set_interface(esp)
requests.set_socket(socket)
However, this code stopped working at some point during the revision of the legacy API. If I try the simpletest
, I get
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "requests_simpletest.py", line 51, in <module>
File "adafruit_requests.py", line 636, in get
File "adafruit_requests.py", line 535, in request
File "adafruit_requests.py", line 420, in _get_socket
File "adafruit_requests.py", line 604, in wrap_socket
AttributeError: 'NoneType' object has no attribute 'TLS_MODE'
Here is the relevant revised code:
class _FakeSSLContext:
def __init__(self, iface):
self._iface = iface
def wrap_socket(self, socket, server_hostname=None):
"""Return the same socket"""
# pylint: disable=unused-argument
return _FakeSSLSocket(socket, self._iface.TLS_MODE)
def set_socket(sock, iface=None):
"""Legacy API for setting the socket and network interface. Use a `Session` instead."""
global _default_session # pylint: disable=global-statement,invalid-name
_default_session = Session(sock, _FakeSSLContext(iface))
if iface:
sock.set_interface(iface)
The _FakeSSLContext
ends up with a None
iface
, and then wrap_socket()
fails because self._iface.TLS_MODE
will fail.
Metadata
Metadata
Assignees
Labels
No labels