Quincy Hsieh commited on
Commit
1974292
·
1 Parent(s): 03514f5

Fix ssl.SSLCertVerificationError with instruction of how to solve it

Browse files
Files changed (2) hide show
  1. README.md +32 -0
  2. app.py +11 -0
README.md CHANGED
@@ -378,6 +378,38 @@ The `/query` endpoint is designed to be called by external RAG evaluation framew
378
 
379
  ---
380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
  ## License
382
 
383
  Apache 2.0
 
378
 
379
  ---
380
 
381
+ ## Troubleshooting
382
+
383
+ ### SSL Certificate Verification Error
384
+
385
+ If you see an error like the one below when running `python app.py`, your machine is most likely behind a **corporate proxy that performs SSL inspection** and has its own root CA that Python does not trust by default.
386
+
387
+ ```
388
+ ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify
389
+ failed: unable to get local issuer certificate
390
+ ```
391
+
392
+ **Fix — point `requests` to your corporate CA bundle:**
393
+
394
+ ```bash
395
+ # macOS / Linux — use the system bundle (adjust path for your distro)
396
+ export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt # Debian/Ubuntu
397
+ export REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt # RHEL/CentOS
398
+
399
+ # Or point to a specific corporate certificate file
400
+ export REQUESTS_CA_BUNDLE=/path/to/corporate-ca.crt
401
+
402
+ # Windows (PowerShell)
403
+ $env:REQUESTS_CA_BUNDLE = "C:\path\to\corporate-ca.crt"
404
+ ```
405
+
406
+ Set the variable **before** running `python app.py`. Both `huggingface_hub` and `sentence-transformers` use the `requests` library, which reads `REQUESTS_CA_BUNDLE` automatically — no code change is needed.
407
+
408
+ > **How to export your corporate CA certificate:**
409
+ > Open the failing URL (`https://huggingface.co`) in your browser, click the padlock icon → View Certificate → export the root CA as a `.crt` / `.pem` file, then point `REQUESTS_CA_BUNDLE` to that file.
410
+
411
+ ---
412
+
413
  ## License
414
 
415
  Apache 2.0
app.py CHANGED
@@ -49,6 +49,17 @@ TOP_K_RESULTS = 3
49
  # HF_TOKEN is set as a Space secret for authenticated Inference API calls
50
  HF_TOKEN = os.environ.get("HF_TOKEN")
51
 
 
 
 
 
 
 
 
 
 
 
 
52
  # Prompt template loaded from file so it can be edited without touching application code
53
  _PROMPT_TEMPLATE_PATH = Path(__file__).parent / "prompts" / "rag_prompt.txt"
54
  RAG_PROMPT_TEMPLATE = _PROMPT_TEMPLATE_PATH.read_text(encoding="utf-8")
 
49
  # HF_TOKEN is set as a Space secret for authenticated Inference API calls
50
  HF_TOKEN = os.environ.get("HF_TOKEN")
51
 
52
+ # Corporate proxy / SSL inspection support:
53
+ # If HTTPS requests to huggingface.co fail with certificate errors, point this
54
+ # variable to your organisation's CA bundle before starting the app.
55
+ # export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt # Linux system bundle
56
+ # export REQUESTS_CA_BUNDLE=/path/to/corporate-ca.crt # custom bundle
57
+ # The requests library (used by huggingface_hub and sentence-transformers) reads
58
+ # this variable automatically — no code change required.
59
+ _ca_bundle = os.environ.get("REQUESTS_CA_BUNDLE") or os.environ.get("SSL_CERT_FILE")
60
+ if _ca_bundle:
61
+ logger.info(f"Using custom CA bundle for HTTPS: {_ca_bundle}")
62
+
63
  # Prompt template loaded from file so it can be edited without touching application code
64
  _PROMPT_TEMPLATE_PATH = Path(__file__).parent / "prompts" / "rag_prompt.txt"
65
  RAG_PROMPT_TEMPLATE = _PROMPT_TEMPLATE_PATH.read_text(encoding="utf-8")