Python 访问控制允许源站存在,但Chrome仍给出CORS错误

Python 访问控制允许源站存在,但Chrome仍给出CORS错误,python,python-3.x,reactjs,google-chrome,flask,Python,Python 3.x,Reactjs,Google Chrome,Flask,我使用前端(在reactJS中)(localhost:8080)调用FlaskAPI(localhost:8000),如下所述: def _build_cors_prelight_response(): response = make_response() response.headers.add("Access-Control-Allow-Origin", "*") response.headers.add("Acces

我使用前端(在reactJS中)(localhost:8080)调用FlaskAPI(localhost:8000),如下所述:

def _build_cors_prelight_response():
    response = make_response()
    response.headers.add("Access-Control-Allow-Origin", "*")
    response.headers.add("Access-Control-Allow-Headers", "*")
    response.headers.add("Access-Control-Allow-Methods", "*")
    return response

def event_stream():
    while True:
        # wait for source data to be available, then push it
        yield 'data: {}\n\n'.format(get_message())

#from: https://stackoverflow.com/questions/25594893/how-to-enable-cors-in-flask
@app.route('/api/events', methods=["GET","OPTIONS"])
def events():
    if request.method == "OPTIONS":  # CORS preflight
        return _build_cors_prelight_response()
    elif request.method=="GET":
        return Response(event_stream(), mimetype="text/event-stream")
尽管我在标题中指定了
访问控制允许原点
,但我仍然在chrome中得到了cors错误(v.81.0.4044.138)

有趣的是,如果我省略了这一行
response.headers.add(“访问控制允许原点”和“*”)
, 我会得到一个不同的错误

在我的flask endpoint中,这是我在控制台中看到的内容:


如何解决这个问题?

嗨,有趣的是,我在使用Chrome 84.0.4147.105版时,在一个
react/django
项目中遇到了确切的问题。在我安装这个chrome扩展之前,它一直存在,尽管我尝试了所有其他解决方案。我真的不明白为什么。也试试看,让我知道结果如何@我也是!我盲目地使用那个扩展来让它工作。那么它也为你工作了?你用say firefox调查过这个问题吗?@MwamiTovi是的,在我问这个问题之前我就知道了,但这不是我想要的,我明白你的意思。嗨,有趣的是,我在使用
Chrome 84.0.4147.105版
时,在
react/django
项目中遇到了确切的问题。在我安装这个chrome扩展之前,它一直存在,尽管我尝试了所有其他解决方案。我真的不明白为什么。也试试看,让我知道结果如何@我也是!我盲目地使用那个扩展来让它工作。那么它也为你工作了?你用say firefox调查过这个问题吗?@MwamiTovi是的,在我问这个问题之前,我就知道了,但这不是我想要的,我明白你的意思。