gpt4 book ai didi

node.js - 为 Axios HTTP 获取请求获取连接 ETIMEDOUT

转载 作者:行者123 更新时间:2023-12-05 05:00:54 66 4
gpt4 key购买 nike

所以我有一个调用 Microsoft Maps API 的 Azure Functions,它可以(有时)工作。但是有时它会在请求期间抛出此错误。请指教。

我的代码:

const options = 
{
host: 'atlas.microsoft.com', //added this later
headers: { 'x-ms-client-id': client_id }
}

//url to get lat/long
let url = 'https://atlas.microsoft.com/search/fuzzy/json?api-version=1.0&subscription-key=' + subscription_key + '&query=' + address + ' USA'

//make req
let res = await axios.get(url, options)

响应/错误:

{
"error": {
"message": "connect ETIMEDOUT XX.XXX.XX.XX:XXX",
"name": "Error",
"stack": "Error: connect ETIMEDOUT XX.XXX.XX.XX:XXX\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)",
"config": {
"url": "https://atlas.microsoft.com/search/fuzzy/json?api-version=1.0&subscription-key=myKey&query=myQuery",
"method": "get",
"headers": {
"Accept": "application/json, text/plain, */*",
"x-ms-client-id": myClientID,
"User-Agent": "axios/0.19.2"
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"host": "atlas.microsoft.com"
},
"code": "ETIMEDOUT"
}
}

最佳答案

我的超时问题的解决方案是添加

host:'atlas.microsoft.com

进入我所有电话的标题。 99% 的连接错误消失了。我还联系了 Mircosoft 支持人员,他们说无论您使用的是 S0 还是 S1 都没有限制,因此不会有什么不同。目前支持正在调查为什么将主机部分添加到请求 header 中会产生如此大的不同。稍后会更新他们的回复。

我问了一个类似的问题并弄清楚了here一些额外的细节。

关于node.js - 为 Axios HTTP 获取请求获取连接 ETIMEDOUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62905979/

66 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com