Skip to content
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

skip ssl import if not available #3078

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions redis/asyncio/connection.py
Expand Up @@ -3,7 +3,6 @@
import enum
import inspect
import socket
import ssl
import sys
import warnings
import weakref
Expand All @@ -27,6 +26,16 @@
)
from urllib.parse import ParseResult, parse_qs, unquote, urlparse

from ..utils import SSL_AVAILABLE

if SSL_AVAILABLE:
import ssl
from ssl import SSLContext

else:
ssl = None
SSLContext = None

# the functionality is available in 3.11.x but has a major issue before
# 3.11.3. See https://github.com/redis/redis-py/issues/2633
if sys.version_info >= (3, 11, 3):
Expand Down Expand Up @@ -826,6 +835,9 @@ def __init__(
ssl_min_version: Optional[ssl.TLSVersion] = None,
**kwargs,
):
if not SSL_AVAILABLE:
raise RedisError("Python wasn't built with SSL support")

self.ssl_context: RedisSSLContext = RedisSSLContext(
keyfile=ssl_keyfile,
certfile=ssl_certfile,
Expand Down Expand Up @@ -893,6 +905,9 @@ def __init__(
check_hostname: bool = False,
min_version: Optional[ssl.TLSVersion] = None,
):
if not SSL_AVAILABLE:
raise RedisError("Python wasn't built with SSL support")

self.keyfile = keyfile
self.certfile = certfile
if cert_reqs is None:
Expand All @@ -914,7 +929,7 @@ def __init__(
self.min_version = min_version
self.context: Optional[ssl.SSLContext] = None

def get(self) -> ssl.SSLContext:
def get(self) -> SSLContext:
if not self.context:
context = ssl.create_default_context()
context.check_hostname = self.check_hostname
Expand Down
7 changes: 6 additions & 1 deletion redis/connection.py
Expand Up @@ -2,7 +2,6 @@
import os
import select
import socket
import ssl
import sys
import threading
import weakref
Expand Down Expand Up @@ -44,6 +43,12 @@
str_if_bytes,
)

if SSL_AVAILABLE:
import ssl

else:
ssl = None

if HIREDIS_AVAILABLE:
import hiredis

Expand Down