python - 即使使用 Auth Pre-Flight 的头,Python Falcon 的 CORS 失败

标签 python angular typescript auth0 falcon

在 Angular2 http.get(url, options) 中使用 OPTIONS 动词 时收到这些错误,即使在 Falcon Rest API 中设置了适当的 CORS header 也是如此。

XMLHttpRequest cannot load http://localhost:8000/names. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

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")

对于非 OPTIONS/正常的 http.get() 请求,这工作正常。

最佳答案

使用 falcon_cors 解决了这个问题,特别是通过设置 allow_all_methods=True

pip install falcon-cors

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])

关于python - 即使使用 Auth Pre-Flight 的头,Python Falcon 的 CORS 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42715002/

相关文章:

javascript - React child 问题( typescript )

javascript - Angular 动画作为单独的文件而不是内联的

python - django2 + python3 : TemplateDoesNotExist

python - 使 Python 类在创建新属性时抛出错误

css - 没有样式应用于 angular-2-dropdown-multiselect

angular - 如何制作可滚动的垫列表

python - 对 Django 的 Ajax 调用发送电子邮件没有响应

python - 添加一条边时使boost图只包含两个顶点

angular - 如何在 angular2-signaturePad 中修复 "Cannot read property ' toDataURL' of undefined"

javascript - 在 Hangman TypeScript 游戏结束时一次显示一个下划线