Я пытаюсь сделать огромное количество запросов к 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
, как
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);)
Позже, Я думал сделать два запроса одновременно.
Для обработки этого я пытаюсь сделать только 2 запроса одновременно, используя ax ios. Пример кода:
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:
I Я использую следующие 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 файлов.)