Fix SSL handshake: use httpx native certificate handling instead of custom SSL context
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
dvirlabs 2026-05-14 18:13:28 +03:00
parent b7ad1218ce
commit a8b6cd2e17

View File

@ -5,7 +5,6 @@ Handles sending WhatsApp messages via Meta's API
import os import os
import httpx import httpx
import certifi import certifi
import ssl
import re import re
import logging import logging
from typing import Optional from typing import Optional
@ -18,19 +17,10 @@ logger = logging.getLogger(__name__)
async def create_http_client() -> httpx.AsyncClient: async def create_http_client() -> httpx.AsyncClient:
""" """
Create an httpx client with proper certificate verification. Create an httpx client with proper certificate verification.
Uses certifi for CA bundle with minimal SSL configuration for compatibility. Uses certifi for CA bundle with httpx's built-in SSL handling for best compatibility.
""" """
# Create SSL context with certifi's CA bundle
ssl_context = ssl.create_default_context(cafile=certifi.where())
# Ensure TLS 1.2+ but allow server to negotiate the version
try:
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
except AttributeError:
# Older Python versions - just use defaults
pass
return httpx.AsyncClient( return httpx.AsyncClient(
verify=ssl_context, verify=certifi.where(),
timeout=httpx.Timeout(30.0, connect=10.0), timeout=httpx.Timeout(30.0, connect=10.0),
http2=False, http2=False,
limits=httpx.Limits(max_keepalive_connections=5, max_connections=10) limits=httpx.Limits(max_keepalive_connections=5, max_connections=10)