Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weather API request cors error

I am trying to get weather data from dark sky api and I keep getting a cors error. Here is my code:

var url = `https://api.darksky.net/forecast/febb2871126cd24613f32a79c32d4158/${lat},${lon}`;
axios.get(url, config).then(response => {
    this.setState({
        ...
    })
}).catch(function (error) {
    console.log(error);
});

I get an error "XMLHttpRequest cannot load https://api.darksky.net/forecast/febb2871126cd24613f32a79c32d4158/38.5815719,-121.4943996. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://ebcperez.github.io' is therefore not allowed access."

like image 732
itsame-ebp Avatar asked Mar 11 '23 09:03

itsame-ebp


1 Answers

I got a same issue But i solved that

https://www.freecodecamp.org/forum/t/calling-openweathermap-api-is-blocked-due-to-cors-header-access-control-allow-origin-missing/191868

like this : "https://cors-anywhere.herokuapp.com/http://samples.openweathermap.org/data/2.5/forecast?appid={your_Api_key}"

or https://api.openweathermap.org/data/2.5/forecast?appid=

So i don't know that url will be didn't occur error

like image 122
joshua.kim Avatar answered Mar 19 '23 16:03

joshua.kim