Curl 有效,但 python 请求因 SSLError 而失败

Curl works but python request fails with SSLError

以下 curl 命令按原样运行,没有任何问题,
curl -H "Authorization: Bearer $AUTH" --cacert "/var/lib/myapp/server-ca.crt" https://myapp.common:2567/service -X GET

在 python、

中实施
headers = {"Authorization": "Bearer {}".format(os.getenv("AUTH"))}
cacert = "/var/lib/myapp/server-ca.crt"
url = "https://myapp.common:2567/service"
response = requests.get(url=url, headers=headers, verify=cacert)

但是失败并出现以下错误

HTTPSConnectionPool(host='myapp.common', port=2567): Max retries exceeded with url: /service
 (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))

对于上下文,此处的 cacert 具有以下信息:
---开始证书---- SOMERANDOMSTRING ---结束证书----

原来问题出在证书上。 OS 信任库中没有我的自签名证书。

Python 请求需要 全链证书 的路径,而不仅仅是 verify 参数的中间证书。请参阅请求文档:SSL Cert Verification

更新后,没有任何问题。