调用大模型API接口超时Connection to ark.cn-beijing.volces.com timed out. (connect timeout=3)‘))”
调用豆包大模型api接口报错,提示连接超时。
·
调用豆包大模型api接口报错,提示连接超时。“requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host=‘ark.cn-beijing.volces.com’, port=443): Max retries exceeded with url: /api/v3/bots/chat/completions (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000023A13978BD0>, ‘Connection to ark.cn-beijing.volces.com timed out. (connect timeout=3)’))”
一、问题
调用豆包大模型api接口报错,提示连接超时。“requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host=‘ark.cn-beijing.volces.com’, port=443): Max retries exceeded with url: /api/v3/bots/chat/completions (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000023A13978BD0>, ‘Connection to ark.cn-beijing.volces.com timed out. (connect timeout=3)’))”
二、代码
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import requests
import json
url = "https://ark.cn-beijing.volces.com/api/v3/bots/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer f989350f-86b0-4ab9-9d20-xxxxxxxxxx"
}
data = {
"model": "bot-xxxxxxxxxx-dn4qh",
"stream": False,
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "你是谁"
}
]
}
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=3, verify=False)
if response.status_code == 200:
print(response.json())
else:
print(f"Request failed with status code {response.status_code}: {response.text}")
三、原因及解决方法
3.1 原因
内网访问OpenAI、豆包等大模型http接口时,需要使用代理。
3.2 解决方法
import os
os.environ['HTTP_PROXY'] = 'http://【华为账号,如x12345678】:【密码】@proxy.huawei.com:8080'
os.environ['HTTPS_PROXY'] = 'http://【华为账号,如x12345678】:【密码】@proxy.huawei.com:8080'
3.3 效果
内网传图有大小限制
火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。
更多推荐
所有评论(0)