httpx.AsyncClient报错ProxyError: 504 Gateway Time-out

场景:

同一个URL,用requests.get能正常获取网页内容,用httpx.get和httpx.AsyncClient.get就不行,要么就报超时,要么就报ProxyError: 504 Gateway Time-out

python 复制代码
import anyio, httpx, requests

url = 'https://my-domain.com/xxx/'

r = requests.get(url, verify=False) # 这个ok
r = httpx.get(url, verify=False) # 这个报错了

async def fetch(url):
    async with httpx.AsyncClient(verify=False) as client:
        return await client.get(url)

r = anyio.run(fetch, url) # 这个也报错了

原因:httpx在Windows下,默认读取系统的代理设置,然后它却不能读到跳过代理的白名单,于是导致不该走代理的网址走了代理,从而引发代理错误。

解决:加上trust_env=False即可

python 复制代码
import anyio, httpx, requests

url = 'https://my-domain.com/xxx/'

r = httpx.get(url, verify=False, trust_env=False)

async def fetch(url):
    async with httpx.AsyncClient(verify=False, trust_env=False) as client:
        return await client.get(url)

r = anyio.run(fetch, url)
相关推荐
Jul1en_2 天前
【SpringCloud】OpenFeign 与 Gateway 讲解与部署
spring·spring cloud·gateway
AI精钢2 天前
修复 AI Gateway 图片 MIME 类型错误:用魔数检测替代扩展名猜测
网络·人工智能·python·gateway·aigc
曲幽4 天前
初探:用 FastAPI 搭建你的第一个 AI Agent 接口
python·ai·llm·agent·fastapi·web·chat·httpx·ollama
Ribou4 天前
Cilium Gateway API 配置手册
gateway
YJlio5 天前
OpenClaw v2026.4.8 更新解析:扩展加载修复、通道配置优化、Slack 代理支持与升级避坑
gateway·自动化运维·版本更新·ai agent·openclaw·slack·插件兼容
weixin_lizhao6 天前
50天独立打造企业级API网关(二):安全防护体系与弹性设计
java·spring boot·安全·spring cloud·gateway
YJlio6 天前
OpenClaw v2026.4.9 更新解析:Memory Dreaming、Control UI、安全修复、插件依赖与升级避坑
gateway·memory·自动化运维·版本更新·ai agent·openclaw·dreaming
code_pgf7 天前
openclaw的gateway详解
人工智能·gateway
zx2859634008 天前
Laravel5.x版本革新特性全解析
mysql·gateway·智能路由器
nvd119 天前
企业级全场景 API 网关实践:基于 Kong Hybrid 模式的跨 VPC 部署与 GitOps 治理
gateway·kong