猎鹰队员没有返回正确的标题

时间:2018-05-20 14:27:47

标签: python cors falconframework

在我的配置中,我有:

cors = CORS(allow_all_origins=True,
            allow_headers_list=['authorization','content-type'],
            allow_all_methods=True)

app = falcon.API(middleware=[
    cors.middleware,
    PeeweeConnectionMiddleware(),
    MultipartMiddleware(),
    auth_middleware,
])

但是当我尝试使用axios发出请求时,firefox尝试预检请求并阻止实际请求,并出现以下错误:

Reason: missing token ‘authorization’ in CORS header ‘Access-Control-Allow-Headers’

我也试过使用allow_all_headers=True,但请求总是失败。可能是什么问题?

在控制台中,我可以阅读:

Aborting response due to unallowed method
[pid: 26577|app: 0|req: 1/1] 127.0.0.1 () {42 vars in 697 bytes} [Sun May 20 16:54:29 2018] OPTIONS /api/v1/auth => generated 0 bytes in 1 msecs (HTTP/1.1 200) 5 headers in 164 bytes (0 switches on core 0)

1 个答案:

答案 0 :(得分:1)

我没有解释为什么使用 allow_all_headers 不适合您,但对我有用的配置如下:

cors = CORS(allow_origins_list=['*'],
            allow_all_origins=True,
            allow_all_headers=True,
            allow_all_methods=True)
相关问题