2017-03-10 3 views
1

Empfangen dieser Fehler bei der Verwendung OPTIONS Verb in Angular2 http.get (URL, Optionen), obwohl die entsprechenden CORS-Header in Falcon Rest API festgelegt sind .CORS Fehler in mit Python Falcon auch mit Köpfen für Auth Pre-Flight

XMLHttpRequest kann http://localhost:8000/names nicht geladen werden. Anforderungsheader Feld Die Autorisierung ist nicht erlaubt von Access-Control-Allow-Header in Preflight-Antwort.

resp.set_header("Access-Control-Allow-Origin", "*") 
     resp.set_header("Access-Control-Allow-Credentials", "true") 
     resp.set_header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT") 
     resp.set_header("Access-Control-Allow-Headers", 
         "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers") 

Für nicht OPTIONS/normal http.get() fordert das funktioniert gut.

+0

wie diese Optionen Anfragen Looks von Angular Bedarf in geeigneter Weise durch Falke Griffe sein ? https://stackoverflow.com/questions/6660019/restful-api-methods-head-options – user2040800

Antwort

1

dies mit falcon_cors gelöst, und zwar durch Einstellung allow_all_methods = True

pip falken cors installieren

from falcon_cors import CORS 

cors = CORS(allow_origins_list=['http://localhost:3000'], 
      allow_all_headers=True, 
      allow_all_methods=True) 

api = falcon.API(middleware=[cors.middleware])