Skip to content

Run on platforms without ssl #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions adafruit_httpserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
except ImportError:
pass

from ssl import SSLContext, create_default_context
from errno import EAGAIN, ECONNRESET, ETIMEDOUT
from sys import implementation
from time import monotonic, sleep
Expand All @@ -34,8 +33,20 @@
from .route import Route
from .status import BAD_REQUEST_400, UNAUTHORIZED_401, FORBIDDEN_403, NOT_FOUND_404

if implementation.name != "circuitpython":
from ssl import Purpose, CERT_NONE, SSLError # pylint: disable=ungrouped-imports
try:
from ssl import SSLContext, create_default_context

try: # ssl imports for C python
from ssl import (
Purpose,
CERT_NONE,
SSLError,
) # pylint: disable=ungrouped-imports
except ImportError:
pass
SSL_AVAILABLE = True
except ImportError:
SSL_AVAILABLE = False


NO_REQUEST = "no_request"
Expand Down Expand Up @@ -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:
Expand Down