I am trying to make an API request by Axios but am getting this error.
Error: Network Error
at e.exports (createError.js:16)
at XMLHttpRequest.g.onerror (xhr.js:117)
Here is the code:
async function getData() {
await axios
.get(
"api.openweathermap.org/data/2.5/weather?q={city name}&appid={api key}"
)
.then(function (data) {
console.log(data);
})
.catch(function (err) {
console.log(err);
});
}
How can I solve this?
Thanks
CodePudding user response:
Try mentioning the right protocol.
"https://api.openweathermap.org/..."
Make sure you're using the right URI path. Also check your connectivity. The values of err
might be worth examining as well.