[英]node.js request module getaddrinfo error
I am trying to hit http://api.openweathermap.org using my assigned apikey ,it is working fine with browser but when i am trying using request module it is giving me error: 我正在尝试使用分配的apikey来访问http://api.openweathermap.org ,它在浏览器中正常工作,但是当我尝试使用请求模块时,它给了我错误:
code is 代码是
apiKey = 'cb1d43c417fce6fa41e4b2251d76fbf2';
city = 'mysore';
url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}`;
var request = require('request');
request(url, function(err, response, body) {
if (err) {
console.log('error:', err);
} else {
console.log('body:', body);
}
});
and the error is; 错误是;
C:\Users\manu.varghese\node-weather>node index.js
error: { Error: getaddrinfo EAI_AGAIN api.openweathermap.org:80
at Object._errnoException (util.js:992:11)
at errnoException (dns.js:55:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
code: 'EAI_AGAIN',
errno: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'api.openweathermap.org',
host: 'api.openweathermap.org',
port: 80 }
Can you try using different DNS servers? 您可以尝试使用其他DNS服务器吗? You can do it in Windows/Mac OS/ Linux or explicitly in Node:
let dns = require('dns'); dns.setServers(['8.8.8.8']);
您可以在Windows / Mac OS / Linux中或在Node中显式地执行此操作:
let dns = require('dns'); dns.setServers(['8.8.8.8']);
let dns = require('dns'); dns.setServers(['8.8.8.8']);
8.8.8.8 is one of Google's DNS servers. 8.8.8.8是Google的DNS服务器之一。 You can try with whatever suits you.
您可以尝试任何适合您的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.