对 maps.google.com 进行大量(可能约为 100000)的 api 调用会导致 getaddrinfo ENOTFOUND 错误
Posted
技术标签:
【中文标题】对 maps.google.com 进行大量(可能约为 100000)的 api 调用会导致 getaddrinfo ENOTFOUND 错误【英文标题】:Making huge number (may be around 100000) of api calls to maps.google.com results in getaddrinfo ENOTFOUND error 【发布时间】:2020-07-11 17:01:42 【问题描述】:我正在尝试向https://maps.googleapis.com/maps/api/place/queryautocomplete/json 发出大量请求。
基本上,我从许多文件中获取一些字符串列表,并尝试向上述 api 发出请求。如果我使用 100 个字符串运行,它工作正常,但如果数量增加,则会返回此错误。
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'maps.googleapis.com',
host: 'maps.googleapis.com',
port: 443,
config:
url:
'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?language=en&key=<api_key>&input=kakanipalem+andhra+pradesh+india',
method: 'get',
headers:
Accept: 'application/json, text/plain, */*',
'User-Agent': 'axios/0.19.2' ,
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 10000,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
data: undefined
一开始我用Promise.all
like
let results = [];
for(let i=0;i<inputStrings.length;i++)
let url = `https://maps.googleapis.com/maps/api/place/queryautocomplete/json?language=en&key=<api_key>&input=$inputStrings[i]+andhra+pradesh+india`;
results.push(axios.get(url))
Promise.all(results).then((refinedResults)=>
//console.log(refinedResults);
).catch(e=>console.log(e);)
后来,我想同时发出两个请求。
为了处理这个问题,我尝试使用 axios 同时发出 2 个请求。 示例代码为:
const cleanInput = async (inputStrings, field) =>
let results = [];
try
let count = 0;
let run = 0;
let requiredResults = [];
let index = 0;
while (count < fieldNames.length && run <= 2)
let tempIndex = 0;
if (results.length < 2)
console.log("pushing", count);
let url = `https://maps.googleapis.com/maps/api/place/queryautocomplete/json?language=en&key=<api_key>&input=$inputStrings[index + tempIndex]+andhra+pradesh+india`;
results.push(axios.get(url));
run += 1;
tempIndex++;
else
let responses = await axios.all(results);
// results = 0;
run -= results.length;
count += results.length;
results = [];
// perform some operation on responses array
catch (e)
console.log(e);
我想知道我是否可以在上面的代码中做任何修改,以便解决这个问题?
另外我想知道哪种方法更适合成功获得结果,或者除了上述两种方法之外还有其他更好的方法吗?
编辑 2:
我正在使用以下 api。输入查询参数取自一个包含所有输入单词的巨大文件。对多个文件重复此过程。
https://maps.googleapis.com/maps/api/place/queryautocomplete/json?language=en&key=<api_key>&input=hyderabad
我的测试文件会是这样的
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
addanki
adoni
kalyanadurg
hyderabad
vizag
因此,例如,如果我的文件总数 = 10,每个文件中的字符串数 = 1500,那么我将使用一个文件,并且对于每个输入(文件中的总共 1500 个输入)我正在进行 api 调用。 (对所有 10 个文件重复。)
【问题讨论】:
除了您的问题被标记为重复之外,还有一些其他相关的问题:Calling too many promises at once、Waiting for some requests to finish before starting others、Promise.all() consumes all my resources。 @jfriend00 我已经尝试了第一个和第二个链接,但我仍然收到 getaddrinfo enotfound maps.google.com port:443 错误。 我不知道。如果您真的在使用我链接的代码并且运行的并发请求不超过 10 个,那么我无法解释。我最好的猜测是,由于请求太多,太快了,谷歌正在限制你的速率。但是,我不知道为什么这会显示为 DNS 错误,除非您的 ISP 对您的 DNS 请求进行速率限制。要进一步调试,我需要有我自己可以尝试的可运行代码/数据。我已重新打开它(不再标记为 dup)。 @jfriend00 我无法与您分享代码,但我会提供一些运行代码的测试数据。我用示例数据编辑了问题。 您使用的是哪个版本的节点? 【参考方案1】:问题可能是由于以下原因
ENOTFOUND
网络连接不稳定会出现错误,请检查你的连接是否稳定,DNS是否正常工作,你可以到浏览器的网络选项卡查看浏览时出现的ENOTFOUND
错误一些网站。如果发生错误,请尝试更新您的 DNS。
由于配额限制,请求有一些限制。请检查您的配额。
【讨论】:
以上是关于对 maps.google.com 进行大量(可能约为 100000)的 api 调用会导致 getaddrinfo ENOTFOUND 错误的主要内容,如果未能解决你的问题,请参考以下文章
Google Maps API v3 返回 ZERO_RESULTS 但 Maps.Google.com 显示正常
Google Maps Javascript API 移动性能问题
Apple Maps 和 Google Maps API 的参数相同吗?
浏览器后退按钮跳转到最后一个位置(如 maps.google.com)