replace ssl.wrap_socket with context.wrap_socket - #23
Open
joga84 wants to merge 1 commit into
Open
Conversation
python 3.12 and later no longer have ssl.wrap_socket, create ssl.create_default_context and use context.wrap_socket instead.
wil
requested changes
Jul 9, 2026
Comment on lines
+80
to
+81
| context = ssl.create_default_context() | ||
| context.load_verify_locations(self.cacerts) |
Member
There was a problem hiding this comment.
context.load_verify_locations will raise a TypeError if self.cacerts is None.
Also, we should still set ciphers if requested:
Suggested change
| context = ssl.create_default_context() | |
| context.load_verify_locations(self.cacerts) | |
| context = ssl.create_default_context(cafile=self.cacerts) | |
| if self.ssl_ciphers: | |
| context.set_ciphers(self.ssl_ciphers) |
| ca_certs=self.cacerts) | ||
| context = ssl.create_default_context() | ||
| context.load_verify_locations(self.cacerts) | ||
| context.load_cert_chain(self.certfile, self.keyfile) |
Member
There was a problem hiding this comment.
context.load_cert_chain will raise a TypeError if self.certfile is None. Add guard:
Suggested change
| context.load_cert_chain(self.certfile, self.keyfile) | |
| if self.certfile or self.keyfile: | |
| context.load_cert_chain(self.certfile, self.keyfile) |
| context = ssl.create_default_context() | ||
| context.load_verify_locations(self.cacerts) | ||
| context.load_cert_chain(self.certfile, self.keyfile) | ||
| context.check_hostname = self.validate_hostname |
Member
There was a problem hiding this comment.
Setting check_hostname here and calling wrap_socket with server_hostname=host is great! It does mean that the if_validate_hostname block that calls match_hostname is redundant (and is probably unreachable if validation fails.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
python 3.12 and later no longer have ssl.wrap_socket, create ssl.create_default_context and use context.wrap_socket instead.