Ok, I figured out what was wrong. It was kind of foolish of me. I had two problems with my code. My first mistake was when specifying the ssl_version I put in TLSv1 when it should have been ssl.PROTOCOL_TLSv1. The second mistake was that I wasn't referencing the wrapped socket, instead I was calling the original socket that I have created. The below code seemed to work for me.

import socket
import ssl

# SET VARIABLES
packet, reply = "<packet>SOME_DATA</packet>", ""
HOST, PORT = 'XX.XX.XX.XX', 4434

# CREATE SOCKET
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)

# WRAP SOCKET
wrappedSocket = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLSv1, ciphers="ADH-AES256-SHA")

# CONNECT AND PRINT REPLY
wrappedSocket.connect((HOST, PORT))
wrappedSocket.send(packet)
print wrappedSocket.recv(1280)

# CLOSE SOCKET CONNECTION
wrappedSocket.close()

Hope this can help somebody!

Answer from Raffi on Stack Overflow
🌐
Python
docs.python.org › 3 › library › ssl.html
ssl — TLS/SSL wrapper for socket objects — Python 3.14.4 ...
Source code: Lib/ssl.py This module provides access to Transport Layer Security (often known as “Secure Sockets Layer”) encryption and peer authentication facilities for network sockets, both clien...
🌐
GitHub
gist.github.com › ndavison › 6a5d97cb8a9091cffa7a
Python socket HTTPS client connection example · GitHub
#!/usr/bin/env python # coding=utf-8 import fire import logging import re import socket import ssl from urllib.parse import urlparse import cchardet as chardet def socket_http(hostname: str, port: int, path: str, http_version: str, method: str): """ Use socket to connect to hostname:port, send GET request, receive response Args: hostname (_type_): _description_ port (_type_): _description_ path (_type_): _description_ """ logging.info( f'Connecting to {hostname}:{port}, send {method} {path} {http_version} request') client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # connect the client
🌐
Pythontic
pythontic.com › ssl › sslsocket › introduction
The SSLSocket class in Python | Pythontic.com
The SSLSocket class is derived from the socket class. The SSLSocket class provides TLS handshake and secure communication over the TCP/IP socket.
🌐
Paullockaby
paullockaby.com › posts › 2019 › 03 › python-ssl-socket-server
Python SSL Socket Server - Paul Lockaby
ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ctx.verify_mode = ssl.CERT_REQUIRED ctx.load_verify_locations("/usr/local/ssl/certs/ca-uwca.pem") ctx.load_cert_chain("/usr/local/ssl/certs/dart.s.uw.edu.pem") # replace the socket with an ssl version of itself self.socket = ctx.wrap_socket(self.socket, server_side=True) # bind the socket and start the server if bind_and_activate: self.server_bind() self.server_activate() class RequestHandler(socketserver.StreamRequestHandler): def handle(self): print("connection from {}:{}".format( self.client_address[0], self.client_address[1], )) try
🌐
GitHub
gist.github.com › marshalhayes › ca9508f97d673b6fb73ba64a67b76ce8
TLS encryption of Python sockets using the "SSL" module · GitHub
TLS encryption of Python sockets using the "SSL" module · Raw · README.md · Follow these steps before trying to run any code. First, generate a Certificate Authority (CA). openssl genrsa -out rootCA.key 2048 · Second, self-sign it. openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 365 -out rootCA.pem ·
🌐
MicroPython
docs.micropython.org › en › latest › library › ssl.html
ssl – SSL/TLS module — MicroPython latest documentation
Wrap the given sock and return a new wrapped-socket object. The implementation of this function is to first create an SSLContext and then call the SSLContext.wrap_socket method on that context object. The arguments sock, server_side and server_hostname are passed through unchanged to the method call.
🌐
Python
docs.python.org › 3.0 › library › ssl.html
ssl — SSL wrapper for socket objects — Python v3.0.1 documentation
To test for the presence of SSL support in a Python installation, user code should use the following idiom: try: import ssl except ImportError: pass else: [ do something that requires SSL support ] This example connects to an SSL server, prints the server’s address and certificate, sends some bytes, and reads part of the response: import socket, ssl, pprint s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # require a certificate from the server ssl_sock = ssl.wrap_socket(s, ca_certs="/etc/ca_certs_file", cert_reqs=ssl.CERT_REQUIRED) ssl_sock.connect(('www.verisign.com', 443)) print(repr(ssl_sock.getpeername())) pprint.pprint(ssl_sock.getpeercert()) print(pprint.pformat(ssl_sock.getpeercert())) # Set a simple HTTP request -- use http.client in actual code.
Find elsewhere
🌐
GitHub
gist.github.com › oborichkin › d8d0c7823fd6db3abeb25f69352a5299
Simple TLS client and server on python · GitHub
import socket import ssl HOST = "127.0.0.1" PORT = 40000 if __name__ == "__main__": server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server = ssl.wrap_socket( server, server_side=True, keyfile="path/to/keyfile", certfile="path/to/certfile" ) server.bind((HOST, PORT)) server.listen(0) while True: connection, client_address = server.accept() while True: data = connection.recv(1024) if not data: break print(f"Received: {data.decode('utf-8')}")
🌐
Medium
medium.com › @cumulus13 › building-bulletproof-ssl-tls-connections-in-python-a-developers-guide-to-secure-socket-4cb1c2d9544e
Building Bulletproof SSL/TLS Connections in Python: A Developer’s Guide to Secure Socket Programming | by Cumulus13 | Medium
August 16, 2025 - The default SSL context is like using “password123” as your password. Sure, it technically provides security, but it’s not going to stop anyone who’s actually trying to break in.
🌐
Markusholtermann
markusholtermann.eu › 2016 › 09 › ssl-all-the-things-in-python
Markus Holtermann — SSL All The Things In Python
That’s the normal Python socket layer. You then create a default SSL context which has all the best practices of the installed Python version. You can furthermore drop some protocols if you feel like it and your requirements allow for that. Next you wrap the socket into an SSL socket.
🌐
Codiga
codiga.io › blog › python-ssl-versions
SSL module in Python: stay secure!
October 17, 2022 - The Python ssl module provides functions and classes to use Secure Sockets Layer (SSL) and Transport Layer Security (TLS) to secure communication both server and client side.
🌐
Jython
jython.org › jython-old-sites › docs › library › ssl.html
17.3. ssl — SSL wrapper for socket objects — Jython v2.5.2 documentation
To test for the presence of SSL support in a Python installation, user code should use the following idiom: try: import ssl except ImportError: pass else: [ do something that requires SSL support ] This example connects to an SSL server, prints the server’s address and certificate, sends some bytes, and reads part of the response: import socket, ssl, pprint s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # require a certificate from the server ssl_sock = ssl.wrap_socket(s, ca_certs="/etc/ca_certs_file", cert_reqs=ssl.CERT_REQUIRED) ssl_sock.connect(('www.verisign.com', 443)) print repr(ssl_sock.getpeername()) print ssl_sock.cipher() print pprint.pformat(ssl_sock.getpeercert()) # Set a simple HTTP request -- use httplib in actual code.
🌐
GitHub
github.com › xliu59 › SSL-TLS_SOCKET
GitHub - xliu59/SSL-TLS_SOCKET: A basic implementation on SSL/TLS socket on both server and client
This is a simple implementation of SSL/TLS web socket (HTTPS) on both client and server end. Keys, certificates and ciphers are only for test use. support user selecting TSL versions, ciphersuites, CA certificate file path as parameters (both ...
Starred by 13 users
Forked by 4 users
Languages   Python 99.1% | HTML 0.9% | Python 99.1% | HTML 0.9%
🌐
TestMu AI Community
community.testmuai.com › ask a question
How to establish an SSL socket connection in Python without certificates - TestMu AI Community
December 19, 2024 - How can I establish an SSL socket connection in Python ssl without needing to provide key files or certificates? I’m trying to create a secure socket connection in Python, but I’m struggling with the SSL part. The serve…
🌐
Blogger
bobthegnome.blogspot.com › 2007 › 08 › making-ssl-connection-in-python.html
Bob's development blog: Making an SSL connection in Python
August 3, 2007 - Basically you just wrap a standard socket with an SSL socket: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('localhost', 12345)) sslSocket = socket.ssl(s) print repr(sslSocket.server()) print repr(sslSocket.issuer()) sslSocket.write('Hello secure socket\n') s.close() The server is a bit more tricky, you need to install pyopenssl (apt-get install python-pyopenssl) for more SSL features.
🌐
W3Schools
w3schools.com › python › ref_module_ssl.asp
Python ssl Module
Python Examples Python Compiler ... {ssl.HAS_SNI}') Try it Yourself » · The ssl module provides TLS/SSL wrapper functionality for socket objects to create secure network connections....
🌐
PyPI
pypi.org › project › ssl
ssl · PyPI
April 20, 2013 - SSL wrapper for socket objects (2.3, 2.4, 2.5 compatible)
      » pip install ssl
    
Published   Apr 20, 2013
Version   1.16
🌐
Snyk
snyk.io › blog › implementing-tls-ssl-python
Implementing TLS/SSL in Python | Snyk
October 16, 2022 - We use the Python SSL library to provide TLS encryption in socket-based communication between Python clients and servers. It uses cryptography and message digests to secure data and detect alteration attempts in the network.