I am trying to connect to the Google Cloud MYSQL server using SSL certificates and the Pyythys module for python with the following line:
connection = pymysql.connect(host=os.environ['SQL_HOST_IP'], user=os.environ['SQL_USER'], password = os.environ['SQL_PASSWORD'],
db='main', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor,
ssl={'key': 'client-key.pem', 'cert': 'client-cert.pem', 'ca': 'server-ca.pem'})
Sorry, I keep getting the following error:
ssl.CertificateError: hostname 'SQL_IP_ADDRESS' doesn't match '$ALIAS_FROM_SELF_SIGNED_SSL_CERT'
I searched for this problem but cannot find a fix that does not involve monkeypatching ssl code to skip the ssl check. I explicitly list the IP address of the SQL node, but the ssl check is suspended during ssl.match_hostname, because the ssl certificates are self-signed with a different host name.
I am sure my keys are valid, as I can connect to them using Ruby (Windows / Linux) and linux mysql CLI. This seems to be a problem with ssl.match_hostname. It looks like this question and this one , but both bypassed the problem.
Is there a way to properly handle self-signed SSL certificates in Python.
source
share