h2csmuggler
h2csmuggler copied to clipboard
DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.w…
Fix the warning below.
./h2csmuggler-proxy.py:49: DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket() retSock = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLS)
Ref. https://docs.python.org/3/library/ssl.html#:~:text=Deprecated%20since%20version%203.7%3A%20Since%20Python%203.2%20and%202.7.9%2C%20it%20is%20recommended%20to%20use%20the%20SSLContext.wrap_socket()%20instead%20of%20wrap_socket().
Hi @riramar , but how to fix in code ?
def establish_tcp_connection(proxy_url): port = proxy_url.port or (80 if proxy_url.scheme == "http" else 443) connect_args = (proxy_url.hostname, int(port))
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
sock.connect(connect_args)
return sock
def send_initial_request(connection, proxy_url, settings_header_value): request = build_initial_request(proxy_url, settings_header_value)
connection.sendall(request)
if proxy_url.scheme == "https":
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_default_certs()
connection = context.wrap_socket(connection, server_hostname=proxy_url.hostname)
return connection