Python 3.x 无法使用python3将TLS连接到GCP云SQL(MySQL)
我犯了这样的错误 ssl.SSLCertVerificationError:[ssl:证书验证失败] 证书验证失败:IP地址不匹配,证书不正确 对“ip_地址”有效。(_.c:1108) server-ca.pem、client-cert.pem和client-key.pem从GCP Cloud SQL的连接选项卡导出Python 3.x 无法使用python3将TLS连接到GCP云SQL(MySQL),python-3.x,google-cloud-sql,Python 3.x,Google Cloud Sql,我犯了这样的错误 ssl.SSLCertVerificationError:[ssl:证书验证失败] 证书验证失败:IP地址不匹配,证书不正确 对“ip_地址”有效。(_.c:1108) server-ca.pem、client-cert.pem和client-key.pem从GCP Cloud SQL的连接选项卡导出 import ssl sc = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) sc.load_verify_locations(cafile=
import ssl
sc = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
sc.load_verify_locations(cafile='./server-ca.pem')
sc.load_cert_chain(certfile='./client-cert.pem', keyfile='./client-key.pem')
#sc.check_hostname = False
async with aiomysql.create_pool(
host=host,
port=port,
user=user,
password=password,
db=db,
ssl=sc
)
此mysql命令可用于访问
我想让你告诉我问题是什么。刚刚遇到同样的问题。您需要设置参数
check_hostname=False
,以便SSL不会尝试验证它
#mysql --ssl-ca=./server-ca.pem --ssl-cert=./client-cert.pem --ssl-key=./client-key.pem --host=host --user=user --password
我正在使用PyMySQL。您可以研究一下在您的案例中,这是如何应用于SSLContext的。即使我更改了不检查的主机名,安全性也有保证吗?
ssl = {
'cert': ...,
'key': ...,
'ca': ...,
'check_hostname': False,
}