Skip to content

Commit 3c1b8e1

Browse files
committed
enable running on platforms without ssl
1 parent b70106b commit 3c1b8e1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

adafruit_httpserver/server.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,20 @@
3434
from .route import Route
3535
from .status import BAD_REQUEST_400, FORBIDDEN_403, NOT_FOUND_404, UNAUTHORIZED_401
3636

37-
if implementation.name != "circuitpython":
38-
from ssl import CERT_NONE, Purpose, SSLError
37+
try:
38+
from ssl import SSLContext, create_default_context
39+
40+
try: # ssl imports for C python
41+
from ssl import (
42+
CERT_NONE,
43+
Purpose,
44+
SSLError,
45+
)
46+
except ImportError:
47+
pass
48+
SSL_AVAILABLE = True
49+
except ImportError:
50+
SSL_AVAILABLE = False
3951

4052

4153
NO_REQUEST = "no_request"
@@ -129,6 +141,8 @@ def __init__(
129141
self.https = https
130142

131143
if https:
144+
if not SSL_AVAILABLE:
145+
raise NotImplementedError("SSL not available on this platform")
132146
self._validate_https_cert_provided(certfile, keyfile)
133147
self._ssl_context = self._create_ssl_context(certfile, keyfile)
134148
else:

0 commit comments

Comments
 (0)