httpx 报 HTTP 407 或代理错误
检查 检查 USERNAME、PASSWORD、HOST、PORT,并确认地址以 http:// 开头、端口是 2222。
处理 从「我的资产」重新复制这些值,再调用 check_exit()。
停止条件 试两次还不行就停下,带订单号提交工单。
更新
curl -x http://USER:PASS@HOST:PORT https://ipinfo.io/json
代理在 CrewAI、LangGraph、LlamaIndex 里放在哪,附一个通用工具函数、三种框架的写法和出口国家检查。
CrewAI、LangGraph、LlamaIndex 决定 Agent 下一步做什么。联网请求是从工具调用的那个函数发出去的,所以代理就该放在那个函数里。我们读的工具定义页把工具写成普通的 Python 函数,没有自带的代理设置。
CrewAI 的 ScrapeWebsiteTool 就是一个例子:它的源码用 requests.get 抓页面,没有传 proxies 参数,所以代理要靠你自己的客户端或环境变量。给整个进程设 HTTPS_PROXY,也会影响其他所有用 requests 的库,所以我们把代理放在工具自己的客户端里。
| 项目 | 工具怎么定义 | 怎么交给 Agent |
|---|---|---|
| CrewAI | crewai.tools 里的 @tool,或继承 BaseTool 并写 _run | Agent 的 tools=[...] |
| LangGraph(LangChain) | langchain.tools 里的 @tool | 放进 tools 列表,用 model.bind_tools(tools) 绑定,在图的工具节点里执行 |
| LlamaIndex | FunctionTool.from_defaults(fn, name=..., description=...) | FunctionAgent 的 tools=[...] |
来源:下方列出的 CrewAI、LangGraph、LlamaIndex 文档页,2026 年 11 月 20 日阅读。导入路径会随版本变化,以你安装的版本为准。
from crewai import Agent
from crewai.tools import tool
from proxy_tools import fetch_page
@tool("Fetch page from the fixed region")
def fetch_page_tool(url: str) -> str:
"""Fetch a web page through the proxy and return its text."""
return fetch_page(url)
researcher = Agent(
role="Regional price checker",
goal="Read the pages you are given and report what a local visitor sees",
backstory="You only read pages through the fetch tool.",
tools=[fetch_page_tool],
)仅为示例:@tool 装饰器和 tools 列表照 CrewAI 文档写。再加上你已有的 Task 和 Crew。
from langchain.tools import tool
from proxy_tools import fetch_page
@tool
def fetch_page_tool(url: str) -> str:
"""Fetch a web page through the proxy and return its text."""
return fetch_page(url)
tools = [fetch_page_tool]
model_with_tools = model.bind_tools(tools) # `model` is your chat model, as in the LangGraph quickstart
# Run the tool calls in the tool node of your StateGraph, as the quickstart does.仅为示例:@tool 装饰器和 bind_tools 照 LangGraph 快速入门写。你自己的模型和图放在外面。
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.tools import FunctionTool
from proxy_tools import fetch_page
fetch_tool = FunctionTool.from_defaults(
fetch_page,
name="fetch_page",
description="Fetch a web page through the proxy and return its text.",
)
agent = FunctionAgent(llm=llm, tools=[fetch_tool]) # `llm` is your LlamaIndex LLM仅为示例:FunctionTool.from_defaults 和 FunctionAgent 照 LlamaIndex 文档写。你自己的 LLM 放进 llm。
国家在生成代理时选。低价线路只能选国家。优质线路还能选州或城市,Agent 查本地页面时很有用。轮换线路每个新连接换一个 IP,复用的连接 IP 不变,所以要读同一个网站好几个页面的 Agent,应该用会话把 IP 固定住。
如果 Agent 要登录某个账号,就改用静态 ISP IP:租期内不轮换,1 天 US$0.50 起。AI Agent 代理类型指南对比了这三种类型。
打开轮换住宅页面,为 Agent 要读取的国家生成一个代理。
打开「我的资产」,复制 HOST、PORT、USERNAME、PASSWORD。用 HTTP 线路、2222 端口拼成 http://LOGIN:PASSWORD@HOST:PORT 作为 PROXY_URL。同一个账号密码在 3333 端口也能走 SOCKS5,工具需要时可以用。
把通用函数存成 proxy_tools.py,PROXY_URL 设成环境变量,调用一次 check_exit()。返回的国家应该是你选的那个。
按上面的写法给自己的框架包一下 fetch_page,并在任务里告诉 Agent:每个页面都用这个工具去取。
检查 检查 USERNAME、PASSWORD、HOST、PORT,并确认地址以 http:// 开头、端口是 2222。
处理 从「我的资产」重新复制这些值,再调用 check_exit()。
停止条件 试两次还不行就停下,带订单号提交工单。
检查 调用 check_exit() 看国家,再和另一个查询站对比。
处理 用正确的国家重新生成代理。
停止条件 两个查询站还是不一致,就把情况记下来,不要把 Agent 反复重跑。
检查 检查页面是不是你的工具取的,而不是某个没有代理设置的内置联网工具取的。
处理 把内置联网工具从 Agent 上拿掉,只给它你自己的工具。
停止条件 不要只靠 HTTPS_PROXY,要把代理放在工具自己的客户端里。
写一个工具,用配置了代理的 HTTP 客户端抓页面,用 @tool 装饰器定义,放进 Agent 的 tools 列表。内置的 ScrapeWebsiteTool 没有传 proxies 参数。
我们读的快速入门把工具定义成 @tool 函数,没有代理设置。代理要配在工具调用的函数里。
生成代理时选国家,再在 Agent 开跑前调一个检查函数,通过代理读 https://ipinfo.io/json。
能,要装 httpx[socks]。同一个账号密码在 3333 端口走 SOCKS5,但 2222 端口的 HTTP 线路不需要额外的包。
只在工具的客户端上设置就不会。整个进程的 HTTPS_PROXY 会影响所有用 requests 的库,所以把代理限定在工具里。
Proxy302 在 GitHub 上公开的同主题配置指南:
官方文档 · 确认日期:
2026 年 11 月 20 日阅读:httpx 用 proxy 参数设置代理,例如 httpx.Client(proxy="http://username:password@localhost:8030");SOCKS 是可选功能,需要 pip install httpx[socks]。
官方文档 · 确认日期:
2026 年 11 月 20 日阅读:工具用 crewai.tools 里的 @tool 装饰器定义,或继承 BaseTool 并写 args_schema 和 _run 方法。
官方文档 · 确认日期:
2026 年 11 月 20 日阅读:Agent 接收 role、goal、backstory 和 tools 列表。
官方文档 · 确认日期:
2026 年 11 月 20 日阅读:工具用 langchain.tools 里的 @tool 装饰器定义,放进列表后用 model.bind_tools(tools) 绑定;图用 langgraph.graph 的 StateGraph 搭建。
官方文档 · 确认日期:
2026 年 11 月 20 日阅读:llama_index.core.tools 里的 FunctionTool.from_defaults(fn, name=..., description=...),以及 llama_index.core.agent.workflow 里的 FunctionAgent(llm=llm, tools=[...])。
外部网站资料 · 确认日期:
2026 年 11 月 20 日阅读:ScrapeWebsiteTool 用 requests.get(url, timeout=15, headers=..., cookies=...) 抓页面,没有传 proxies 参数。
官方文档 · 确认日期:
2026 年 11 月 20 日阅读:PRAW 基于 requests,而 requests 支持 HTTP_PROXY 和 HTTPS_PROXY 环境变量。
产品观察 · 确认日期:
站点产品事实表,2026 年 11 月 10 日对照控制台、后端和价格表核对:按 IP 租用价格(US$,1 PTC = US$1)、租期、协议与端口、国家、数量上限、无免费试用。
注册账号、充值一次,就能选动态住宅、静态 ISP 或数据中心 IP,几分钟配进你的浏览器。