Skip to content

Commit ca65b59

Browse files
authored
Merge pull request #103 from Neradoc/work-when-no-ssl
Run on platforms without ssl
2 parents b70106b + 9ed25b8 commit ca65b59

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

adafruit_httpserver/server.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
pass
1414

1515
from errno import EAGAIN, ECONNRESET, ETIMEDOUT
16-
from ssl import SSLContext, create_default_context
1716
from sys import implementation
1817
from time import monotonic, sleep
1918
from traceback import print_exception
@@ -34,8 +33,20 @@
3433
from .route import Route
3534
from .status import BAD_REQUEST_400, FORBIDDEN_403, NOT_FOUND_404, UNAUTHORIZED_401
3635

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

4051

4152
NO_REQUEST = "no_request"
@@ -129,6 +140,8 @@ def __init__(
129140
self.https = https
130141

131142
if https:
143+
if not SSL_AVAILABLE:
144+
raise NotImplementedError("SSL not available on this platform")
132145
self._validate_https_cert_provided(certfile, keyfile)
133146
self._ssl_context = self._create_ssl_context(certfile, keyfile)
134147
else:

0 commit comments

Comments
 (0)