GIScience / openrouteservice

🌍 The open source route planner api with plenty of features.
https://openrouteservice.org
GNU General Public License v3.0
1.33k stars 379 forks source link

CORS Error when requesting directions api #151

Closed Maj0rrush closed 6 years ago

Maj0rrush commented 6 years ago

Hey,

since this morning I always get an error when I make a request via dev machine -> localhost.

Failed to load https://api.openrouteservice.org/directions?api_key=$APIKEY&coordinates=6.93651887827815%2C51.11207410151039%7C6.951238841352023%2C51.09800812671892&profile=foot-walking&geometry_format=geojson

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 403.

TimMcCauley commented 6 years ago

@Maj0rrush was this working before? I just tried it myself and it's working from my localhost - can you please run the following script in a cgi-binfolder via python -m CGIHTTPServer 8000 (run this on the same level) and let me know what the response is?

#!/usr/bin/env python

import cgi
import requests
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')

url = "https://api.openrouteservice.org/directions"

querystring = {"api_key":"xxx","elevation":"true","profile":"driving-car","preference":"recommended","language":"hu","geometry":"true","geometry_format":"geojson","coordinates":"20.1810948,46.269903799999994|27.867883,43.229733|20.001267,45.972317"}

headers = {
    'Content-Type': "application/json",
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print response.text
Maj0rrush commented 6 years ago

Hi .. i have requestet a new api key and now it works again ;-) ... Issue closed for me ...

leonheess commented 4 years ago

I have this exact issue.

Example-Request: https://api.openrouteservice.org/directions?api_key=%KEY%&coordinates=9.68473,47.372486|14.033405,48.156815&profile=cycling-regular&format=json&geometry=true&geometry_format=geojson&elevation=true&extra_info=surface

In the Browser I get: Access to fetch at %URL% from origin 'https://bicyculty.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

And when opening it directly I get: image