diff --git a/adafruit_httpserver/server.py b/adafruit_httpserver/server.py index 992eae5..e15a428 100644 --- a/adafruit_httpserver/server.py +++ b/adafruit_httpserver/server.py @@ -13,7 +13,6 @@ pass from errno import EAGAIN, ECONNRESET, ETIMEDOUT -from ssl import SSLContext, create_default_context from sys import implementation from time import monotonic, sleep from traceback import print_exception @@ -34,8 +33,20 @@ from .route import Route from .status import BAD_REQUEST_400, FORBIDDEN_403, NOT_FOUND_404, UNAUTHORIZED_401 -if implementation.name != "circuitpython": - from ssl import CERT_NONE, Purpose, SSLError +try: + from ssl import SSLContext, create_default_context + + try: # ssl imports for C python + from ssl import ( + CERT_NONE, + Purpose, + SSLError, + ) + except ImportError: + pass + SSL_AVAILABLE = True +except ImportError: + SSL_AVAILABLE = False NO_REQUEST = "no_request" @@ -129,6 +140,8 @@ def __init__( self.https = https if https: + if not SSL_AVAILABLE: + raise NotImplementedError("SSL not available on this platform") self._validate_https_cert_provided(certfile, keyfile) self._ssl_context = self._create_ssl_context(certfile, keyfile) else: diff --git a/docs/starting_methods.rst b/docs/starting_methods.rst index 757f966..1b3a289 100644 --- a/docs/starting_methods.rst +++ b/docs/starting_methods.rst @@ -28,13 +28,11 @@ it may not be able to access the internet. Manual Ethernet --------------- -Most of the time, the WiFi will be a preferred way of connecting to the network. -Nevertheless it is also possible to use Ethernet instead of WiFi. -The only difference in usage is related to configuring the ``socket_source`` differently. +Ethernet can also be used to connect to the location network. .. literalinclude:: ../examples/httpserver_simpletest_manual_ethernet.py :caption: examples/httpserver_simpletest_manual_ethernet.py - :emphasize-lines: 7,10,12-24,37 + :emphasize-lines: 11-20 :linenos: Automatic WiFi using ``settings.toml`` diff --git a/examples/httpserver_simpletest_manual_ethernet.py b/examples/httpserver_simpletest_manual_ethernet.py index 5d668b8..80ce1af 100644 --- a/examples/httpserver_simpletest_manual_ethernet.py +++ b/examples/httpserver_simpletest_manual_ethernet.py @@ -2,9 +2,9 @@ # # SPDX-License-Identifier: MIT +import adafruit_connection_manager import board import digitalio -from adafruit_wiznet5k import adafruit_wiznet5k_socket as socket from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K from adafruit_httpserver import Request, Response, Server @@ -20,10 +20,9 @@ # Initialize ethernet interface with DHCP eth = WIZNET5K(spi_bus, cs) -# Set the interface on the socket source -socket.set_interface(eth) +pool = adafruit_connection_manager.get_radio_socketpool(eth) -server = Server(socket, "/static", debug=True) +server = Server(pool, "/static", debug=True) @server.route("/")