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)
相关推荐
七夜zippoe21 小时前
OpenClaw Gateway 服务:启动、停止、监控
微服务·架构·gateway·监控·openclaw
arvin_xiaoting1 天前
OpenClaw学习总结_I_核心架构系列_Gateway架构详解
学习·架构·llm·gateway·ai-agent·飞书机器人·openclaw
柯儿的天空1 天前
【OpenClaw 全面解析:从零到精通】第007篇:流量枢纽——OpenClaw Gateway 网关深度解析
人工智能·gpt·ai作画·gateway·aigc·ai编程·ai写作
Zhao_yani1 天前
微服务核心组件:Gateway
java·微服务·gateway
gallonyin1 天前
【企业级龙虾】LLM Gateway 工程化落地:配置中心、429故障转移与统计持久化实战
gateway·openclaw
道清茗2 天前
【Kubernetes知识点问答题】Kustomize、CRD 与 Gateway API
容器·kubernetes·gateway
专注_每天进步一点点2 天前
xxop网关 → APISIX集群(ApisixRoute) → 业务gateway模块 和 Serverless架构 区别和联系
架构·serverless·gateway
专注_每天进步一点点2 天前
流量从bcop网关到apisixroute,再到应用的gateway模块,再到其他服务
docker·kubernetes·gateway
MadPrinter3 天前
OpenClaw Gateway 卡死假死问题完整诊断与预防方案
gateway
RemainderTime3 天前
(十一)Spring Cloud Alibaba 2023.x:构建分布式全链路日志追踪体系
分布式·微服务·架构·gateway