网络环境
- windows 11 作为宿主机,wsl 作为开发环境;
问题
- 在 wsl 使用了 claude code 进行 vibe coding,但是发现 claude code 网络 api.minimaxi.com 请求不出
目标
- 解决网络问题,让 claude code 可以正常请求。
结果
【顺利解决】
根本原因:因为本地的 env 配置 http_proxy(192.168.3.xxx),导致 claude 的请求走了 http_proxy 的链路。
主要内容
- 分析这个网络问题,记录解决步骤,
1. 逐层测试 TCP/IP 协议栈的可达性
IP 层
- ping api.minimaxi.com
bash
$ ping api.minimaxi.com
PING lb-ali.minimaxi.com (8.130.45.254) 56(84) bytes of data.
64 bytes from 8.130.45.254 (8.130.45.254): icmp_seq=1 ttl=88 time=45.7 ms
64 bytes from 8.130.45.254 (8.130.45.254): icmp_seq=2 ttl=88 time=45.7 ms
64 bytes from 8.130.45.254 (8.130.45.254): icmp_seq=3 ttl=88 time=44.5 ms
TCP 层
bash
$ dig +short api.minimaxi.com
lb-ali.minimaxi.com.
8.130.49.194 # 目标主机的 ip
8.130.45.254
$ sudo tcpdump -i any 'host 8.130.45.254 or host 8.130.49.194' -v
# 新开终端
$ export CLAUDE_ENDPOINT="https://api.minimaxi.com/anthropic/v1/messages"
$ curl -X POST "$CLAUDE_ENDPOINT" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-3-haiku-20240307",
"max_tokens": 100,
"messages": [
{"role": "user", "content": "Hello, Claude"}
]
}'
{"type":"error","error":{"type":"authentication_error","message":"login fail: Please carry the API secret key in the 'Authorization' field of the request header"},"request_id":"055df91249b0f5d119ff78a51be71488"}
问题点:tcpdump 没有捕捉到 tcp 的数据包。问题在 TCP/IP 或者更加上层,并在出现在 wsl 的配置中。
2. 本机出现了请求成功,但没有抓到包。从代理角度分析
bash
export | grep -i proxy
嗯,果然是设置了 HTTP_PROXY 代理,是此前自己做测试的时候留下的。去除掉就可以了。
相关命令
- dig
- tcpdump
- ping
- export