Hello,
I'm trying to make a function that can setup a connection to both IPv4 and IPv6. The function below works as expected when passed an IPv4 string, but when passed an IPv6 string it throws an error: [Errno 101] Network is unreachable. I'm not sure how to fix this because the documentation for socket.create_connection() states "if host is a non-numeric hostname, it will try to resolve it for both AF_INET and AF_INET6, and then try to connect to all possible addresses in turn until a connection succeeds". Maybe I'm misunderstanding something here?
to avoid confusion, this function is nested within another function
example IPv6 string: '2607:f8b0:4006:821::2004'
raw_socket = socket.create_connection((ip_address, 443))
raw_socket.settimeout(timeout)
ssl_context = ssl.create_default_context()
if not verify_ssl:
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
ssl_sock = ssl_context.wrap_socket(raw_socket, server_hostname=domain)
connection = HTTPSConnection(domain, 443)
connection.sock = ssl_sock
return connection, ssl_sock```