解决Antropic无法访问问题解决
1. 问题描述
通过Anthropic调用大模型,返回Error code: 403 - {'error': {'type': 'forbidden', 'message': 'Request not allowed'}}
2.原因分析
在开启vpn的情况下,通过发送post请求可以正常调用,通过Anthropic无法调用,可能是因为访问环境引起的,需要配置代理
3. 具体实现
custom_httpx_client = httpx.Client(
transport=httpx.HTTPTransport(
proxy=httpx.Proxy(
url="http://your_proxy_address:port"
)
),
timeout=30.0
)
# 初始化Anthropic客户端
client = Anthropic(
api_key="your-api-key",
http_client=custom_httpx_client,
)
# 发送请求
response = client.messages.create(
model="claude-3-7-sonnet-20250219",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "hello?"
}
]
)
print(response.content)
4. 参考资料
4.1 https://blog.csdn.net/u012246511/article/details/147618137
4.2 https://github.com/anthropics/anthropic-sdk-typescript/issues/457
浙公网安备 33010602011771号