Skip to content

Fix ssl deprecate warn #283

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

Merged
merged 1 commit into from
May 12, 2024
Merged
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
15 changes: 9 additions & 6 deletions ws4py/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ def __init__(self, url, protocols=None, extensions=None,
self.exclude_headers = exclude_headers or []
self.exclude_headers = [x.lower() for x in self.exclude_headers]

if self.scheme == "wss":
# Prevent check_hostname requires server_hostname (ref #187)
if "cert_reqs" not in self.ssl_options:
self.ssl_options["cert_reqs"] = ssl.CERT_NONE

self._parse_url()

if self.unix_socket_path:
Expand Down Expand Up @@ -211,7 +206,15 @@ def connect(self):
"""
if self.scheme == "wss":
# default port is now 443; upgrade self.sender to send ssl
self.sock = ssl.wrap_socket(self.sock, **self.ssl_options)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
if self.ssl_options.get('certfile', None):
context.load_cert_chain(self.ssl_options.get('certfile'), self.ssl_options.get('keyfile'))
# Prevent check_hostname requires server_hostname (ref #187)
if "cert_reqs" not in self.ssl_options:
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

self.sock = context.wrap_socket(self.sock)
self._is_secure = True

self.sock.connect(self.bind_addr)
Expand Down