> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-revert-104359-revert-104251-parquet-single.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ClickHouse の SSL 証明書検証エラーの解決方法

> SSL Exception CERTIFICATE_VERIFY_FAILED エラーを解決する方法を説明します。

<div id="resolving-ssl-certificate-verify-error-in-clickhouse">
  ## ClickHouse におけるコード 210 の SSL 証明書検証エラーの解決
</div>

このエラーは通常、次のように報告されます。

`Code: 210. DB::NetException: SSL Exception: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED`

<div id="cause-of-the-error">
  ## エラーの原因
</div>

このエラーは、`clickhouse-client` を使用して ClickHouseサーバーへの接続を試行している際に発生します。原因は、次のいずれかです。

* クライアントの設定ファイル `config.xml` に、マシンのデフォルトの CA ストア内のルート証明書が含まれていない
* 自己署名証明書または内部 CA 証明書が設定されていない

<div id="solution">
  ## 解決策
</div>

内部CAまたは自己署名CAを使用する場合は、クライアントディレクトリ (例: `/etc/clickhouse-client`) 内の `config.xml` でCAルート証明書を設定し、既定の場所にある既定のルートCA証明書を読み込まないようにします。

以下は設定例です。

```xml theme={null}
<openSSL>
    <client>
        <loadDefaultCAFile>false</loadDefaultCAFile>
        <caConfig>/etc/clickhouse-server/certs/marsnet_ca.crt</caConfig>
        <cacheSessions>true</cacheSessions>
        <disableProtocols>sslv2,sslv3</disableProtocols>
        <preferServerCiphers>true</preferServerCiphers>
        <invalidCertificateHandler>
            <name>RejectCertificateHandler</name>
        </invalidCertificateHandler>
    </client>
</openSSL>
```

<div id="python-clients-on-macos">
  ## macOS 上の Python クライアント
</div>

Python クライアントでは、このエラーは通常次のように表示されます。

`ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate`

macOS では、python.org の Python ビルドは、システムのキーチェーンではなく OpenSSL のデフォルトパスを通じて証明書を検証します。新規インストール直後は、これらのパスがルート証明書バンドルを指していません。インストーラーには [certifi](https://pypi.org/project/certifi/) が含まれていますが、同梱の `Install Certificates.command` スクリプトを実行するまで、OpenSSL のデフォルトの場所にはリンクされません。そのため、それまでは証明書自体は有効でも、クライアントは ClickHouse Cloud のサーバー証明書を検証できません。これは Python 3.11 に限らず、python.org の macOS ビルド全般 (Python 3.6 以降) に影響します。

`Install Certificates.command` を実行して、certifi を OpenSSL のデフォルト証明書パスにリンクしてください。パス内のバージョンは、インストール環境に合わせて調整してください。

```bash theme={null}
open "/Applications/Python 3.11/Install Certificates.command"
```

または、クライアントが certifi バンドルを直接使用するように設定します。[ClickHouse Connect](/ja/integrations/language-clients/python/index) は自動的に certifi にフォールバックしないため、`ca_cert` パラメータでバンドルを渡してください。

```python theme={null}
import certifi
import clickhouse_connect

client = clickhouse_connect.get_client(
    host='HOSTNAME.clickhouse.cloud',
    port=8443,
    username='default',
    password='YOUR_SECRET_PASSWORD',
    ca_cert=certifi.where(),
)
```

<div id="additional-resources">
  ## 参考資料
</div>

[`clickhouse-client` の設定に関するドキュメント](/ja/concepts/features/interfaces/client#configuration_files)を参照してください。
