适配httpx0.28
This commit is contained in:
@@ -437,7 +437,7 @@ class Agent:
|
|||||||
semaphore = asyncio.Semaphore(max_concurrent)
|
semaphore = asyncio.Semaphore(max_concurrent)
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
||||||
proxies = get_httpx_proxies() if self.system_proxy_enable else None
|
proxies = get_httpx_proxies(asyn=True) if self.system_proxy_enable else None
|
||||||
|
|
||||||
limits = httpx.Limits(
|
limits = httpx.Limits(
|
||||||
max_connections=self.max_concurrent * 2, # 为重试和并发预留空间
|
max_connections=self.max_concurrent * 2, # 为重试和并发预留空间
|
||||||
@@ -445,7 +445,7 @@ class Agent:
|
|||||||
)
|
)
|
||||||
|
|
||||||
async with httpx.AsyncClient(
|
async with httpx.AsyncClient(
|
||||||
trust_env=False, proxies=proxies, verify=False, limits=limits
|
trust_env=False, mounts=proxies, verify=False, limits=limits
|
||||||
) as client:
|
) as client:
|
||||||
|
|
||||||
async def send_with_semaphore(p_text: str):
|
async def send_with_semaphore(p_text: str):
|
||||||
@@ -688,9 +688,9 @@ class Agent:
|
|||||||
max_connections=self.max_concurrent * 2, # 允许连接复用
|
max_connections=self.max_concurrent * 2, # 允许连接复用
|
||||||
max_keepalive_connections=self.max_concurrent, # 保持活跃连接
|
max_keepalive_connections=self.max_concurrent, # 保持活跃连接
|
||||||
)
|
)
|
||||||
proxies = get_httpx_proxies() if self.system_proxy_enable else None
|
proxies = get_httpx_proxies(asyn=False) if self.system_proxy_enable else None
|
||||||
with httpx.Client(
|
with httpx.Client(
|
||||||
trust_env=False, proxies=proxies, verify=False, limits=limits
|
trust_env=False, mounts=proxies, verify=False, limits=limits
|
||||||
) as client:
|
) as client:
|
||||||
clients = itertools.repeat(client, len(prompts))
|
clients = itertools.repeat(client, len(prompts))
|
||||||
with ThreadPoolExecutor(max_workers=self.max_concurrent) as executor:
|
with ThreadPoolExecutor(max_workers=self.max_concurrent) as executor:
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
# SPDX-FileCopyrightText: 2025 QinHan
|
# SPDX-FileCopyrightText: 2025 QinHan
|
||||||
# SPDX-License-Identifier: MPL-2.0
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
from urllib.request import getproxies
|
from urllib.request import getproxies
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
def get_httpx_proxies(asyn=True):
|
||||||
def get_httpx_proxies():
|
|
||||||
https_proxy = getproxies().get("https")
|
https_proxy = getproxies().get("https")
|
||||||
http_proxy = getproxies().get("http")
|
http_proxy = getproxies().get("http")
|
||||||
proxies = {}
|
proxies = {}
|
||||||
if https_proxy:
|
if https_proxy:
|
||||||
proxies["https://"] = https_proxy
|
# print(f"检测到系统代理:{https_proxy}")
|
||||||
|
if asyn:
|
||||||
|
proxies["https://"] = httpx.AsyncHTTPTransport(proxy=https_proxy)
|
||||||
|
else:
|
||||||
|
proxies["https://"] = httpx.HTTPTransport(proxy=https_proxy)
|
||||||
if http_proxy:
|
if http_proxy:
|
||||||
proxies["http://"] = http_proxy
|
# print(f"检测到系统代理:{http_proxy}")
|
||||||
|
if asyn:
|
||||||
|
proxies["http://"] = httpx.AsyncHTTPTransport(proxy=http_proxy)
|
||||||
|
else:
|
||||||
|
proxies["https://"] = httpx.HTTPTransport(proxy=https_proxy)
|
||||||
return proxies
|
return proxies
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ description = "文件翻译工具"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"httpx==0.27.2",
|
|
||||||
"fastapi[standard]>=0.115.12",
|
"fastapi[standard]>=0.115.12",
|
||||||
"jsonpath-ng>=1.7.0",
|
"jsonpath-ng>=1.7.0",
|
||||||
"openpyxl>=3.1.5",
|
"openpyxl>=3.1.5",
|
||||||
@@ -19,6 +18,7 @@ dependencies = [
|
|||||||
"pymdown-extensions>=10.16.1",
|
"pymdown-extensions>=10.16.1",
|
||||||
"chardet>=5.2.0",
|
"chardet>=5.2.0",
|
||||||
"pysubs2>=1.8.0",
|
"pysubs2>=1.8.0",
|
||||||
|
"httpx>=0.28.1",
|
||||||
]
|
]
|
||||||
dynamic = ["version"]
|
dynamic = ["version"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user