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