I am trying to get weather data from dark sky api and I keep getting a cors error. Here is my code:
var url = `/${lat},${lon}`;
axios.get(url, config).then(response => {
this.setState({
...
})
}).catch(function (error) {
console.log(error);
});
I get an error "XMLHttpRequest cannot load .5815719,-121.4943996. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access."
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/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/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."
Share Improve this question asked Dec 19, 2016 at 2:50 itsame-ebpitsame-ebp 631 gold badge1 silver badge4 bronze badges 3- yep, you'll get that if the server doesn't allow cross origin resource sharing – Jaromanda X Commented Dec 19, 2016 at 2:56
-
check it in
chrome
, IE is strict on CORS. – ling7334 Commented Dec 19, 2016 at 3:04 - @ling7334 - all browsers are strict on CORS - there was a setting in chrum that allowed you to turn off CORS logic, but running the browser in that way would mean that you've opened up your system to every known 90's exploit that ever existed – Jaromanda X Commented Dec 19, 2016 at 3:08
3 Answers
Reset to default 3I got a same issue But i solved that
https://www.freecodecamp/forum/t/calling-openweathermap-api-is-blocked-due-to-cors-header-access-control-allow-origin-missing/191868
like this : "https://cors-anywhere.herokuapp./http://samples.openweathermap/data/2.5/forecast?appid={your_Api_key}"
or https://api.openweathermap/data/2.5/forecast?appid=
So i don't know that url will be didn't occur error
Looks like the Darksky API server doesn't allow CORS, so you won't be able to make this request from your browser.
A possible solution would be to issue the API request from your application server, and then just display it on the front end.
Here’s an explanation of why this happens. The tl;dr is to use a CORS proxy for your requests. Prepend https://cors-anywhere.herokuapp./ to your API’s URL. https://cors-anywhere.herokuapp./http://api.openweathermap...
i hope this works for you