fix: add Feishu TLS compatibility and environment template
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import os
|
||||
import ssl
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -25,6 +26,18 @@ DEFAULT_BATCH_SIZE = 500
|
||||
DEFAULT_HTTP_RETRIES = 3
|
||||
DEFAULT_HTTP_RETRY_DELAY = 2.0
|
||||
|
||||
|
||||
def create_feishu_tls12_context() -> ssl.SSLContext:
|
||||
"""Create a verified TLS 1.2 context for Feishu API requests."""
|
||||
|
||||
context = ssl.create_default_context()
|
||||
context.minimum_version = ssl.TLSVersion.TLSv1_2
|
||||
context.maximum_version = ssl.TLSVersion.TLSv1_2
|
||||
return context
|
||||
|
||||
|
||||
FEISHU_HTTP_OPENER = request.build_opener(request.HTTPSHandler(context=create_feishu_tls12_context()))
|
||||
|
||||
DB_QUERY = """
|
||||
SELECT
|
||||
fs.支付时间 AS 支付时间,
|
||||
@@ -181,7 +194,7 @@ def feishu_request(
|
||||
for attempt in range(1, retries + 1):
|
||||
req = request.Request(url=url, method=method, headers=headers, data=data)
|
||||
try:
|
||||
with request.urlopen(req, timeout=60) as resp:
|
||||
with FEISHU_HTTP_OPENER.open(req, timeout=60) as resp:
|
||||
body = resp.read().decode("utf-8")
|
||||
break
|
||||
except error.HTTPError as exc:
|
||||
@@ -202,7 +215,7 @@ def feishu_request(
|
||||
time.sleep(sleep_seconds)
|
||||
continue
|
||||
raise RuntimeError(f"Feishu API 请求失败: {exc.code} {detail}") from exc
|
||||
except error.URLError as exc:
|
||||
except (error.URLError, ssl.SSLError) as exc:
|
||||
log(
|
||||
f"Feishu API 网络异常: method={method} url={url} "
|
||||
f"attempt={attempt}/{retries} error={exc}",
|
||||
|
||||
Reference in New Issue
Block a user