🍣
CERTIFICATE_VERIFY_FAILEDでdbt depsが死ぬ時
概要
会社pcのセキュリティ周りの設定でネットワーク通信に発生する以下のようなトラブルの対処
❯ dbt deps
00:21:03 Running with dbt=1.7.6
00:21:09 Encountered an error:
External connection exception occurred: HTTPSConnectionPool(host='hub.getdbt.com', port=443): Max retries exceeded with url: /api/v1/index.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')))
内容
以下のスクリプトを実行してみて確かに疎通できてないことを確認する
import os
import requests
from requests.utils import DEFAULT_CA_BUNDLE_PATH
url = "https://hub.getdbt.com"
try:
response = requests.get(url, timeout=10)
print("It worked")
except Exception as e:
print("It didn't work\n")
print(f"HTTPS_PROXY: {os.environ.get('HTTPS_PROXY')}")
print(f"REQUESTS_CA_BUNDLE: {os.environ.get('REQUESTS_CA_BUNDLE')}")
print(f"CURL_CA_BUNDLE: {os.environ.get('CURL_CA_BUNDLE')}")
print(f"DEFAULT_CA_BUNDLE_PATH: {DEFAULT_CA_BUNDLE_PATH}")
実行結果にある DEFAULT_CA_BUNDLE_PATH, HTTPS_PROXY は次使う
❯ python a.py
It didn't work
HTTPS_PROXY: http://127.0.0.1:9000
REQUESTS_CA_BUNDLE: None
CURL_CA_BUNDLE: None
DEFAULT_CA_BUNDLE_PATH: venv/lib/python3.11/site-packages/certifi/cacert.pem
以下のコマンドを実行
❯ pip install --upgrade certifi
❯ pip install pip-system-certs # windows の場合は pip install python-certifi-win32 だがこれは未検証
❯ export REQUESTS_CA_BUNDLE=/venv/lib/python3.11/site-packages/certifi/cacert.pem
❯ export HTTPS_PROXY=http://127.0.0.1:9000
もう一度疎通確認してみる
❯ python a.py
It worked
冒頭の問題が解決していることを確認
❯ dbt deps
00:36:26 Running with dbt=1.7.6
00:36:29 Updating lock file in file path: /dbt/package-lock.yml
00:36:29 Installing dbt-labs/codegen
00:36:30 Installed from version 0.12.1
00:36:30 Up to date!
00:36:30 Installing https://github.com/EqualExperts/dbt-unit-testing
00:36:33 Installed from revision e54329c3971c8c397f284a36de6a627832a24263
00:36:33 Installing dbt-labs/dbt_utils
00:36:33 Installed from version 1.1.1
00:36:33 Up to date!
Discussion