Python 3.x 对飞行前请求的响应不';无法通过访问控制检查:它没有HTTP ok状态。打开

Python 3.x 对飞行前请求的响应不';无法通过访问控制检查:它没有HTTP ok状态。打开,python-3.x,reactjs,flask,Python 3.x,Reactjs,Flask,当我与flask(python)图像上传集成时。 上一次我也面临着这个问题。 从源“”获取“”的访问已被CORS策略阻止:对飞行前请求的响应未通过访问控制检查:它没有HTTP ok状态 class VApiPage extends React.Component { constructor(props) { super(props); this._path= this._path.bind(this); this.state={

当我与flask(python)图像上传集成时。 上一次我也面临着这个问题。 从源“”获取“”的访问已被CORS策略阻止:对飞行前请求的响应未通过访问控制检查:它没有HTTP ok状态

class VApiPage extends React.Component {
    constructor(props) {
    super(props);
        this._path= this._path.bind(this);
        this.state={
            flag:1,
            path: "",
            res:"",
            img:""
        }
    }

    _path(e){
        this.setState({
            path:e.target.value
        });

    }

    _results(){
        let img1= this.state.path;
        let str1;
        let str;
        this.setState({img:img1});

            str="http://0.0.0.0:4000/"+ str1 +"/"+this.state.path;

        fetch(str, {
            method: "POST",
            headers: {
                "Access-Control-Allow-Origin": "*"
        },
    })

        .then(res => res.json())
        .then(res => {
              if(window.location.pathname.split("/")[4]==="gender"){
                    this.setState({
                    res: res.Gender
                });
            }
            else if(window.location.pathname.split("/")[4]==="emotion"){
                this.setState({
                res: res.Emotion
            });
        }

            });
    }

    render() {
    return (
      <div className="analysis">

        <div className="col-md-3" />

          <div className="col-md-6 visionresult">


        </div>

        <div className= "col-md-12 test">

          <div className="col-md-1 url">
                    <form>

                    <input type = "file" name = "image" onChange={(e)=>{console.log(e.target.files[0].name);
                                                                                                                             this.setState({path:e.target.files[0].name,
                                                                                                                                                            img:e.target.files[0].name});}}/>

                    </form>
           </div>

          <div className="col-md-8 " >
            <textarea className="links" onChange={(e)=>this._path(e)} placeholder="" cols="100" rows="1"></textarea>
          </div>

                </div>

                    <div className={this.state.flag===1?"col-md-1 results":""} onClick={()=>this._results()}>
                        <button type="button" className="btn btn-outline-secondary">Analysis</button>
                    </div>

                    <div className="col-md-12">
                    <div className="col-md-2 imgdisplay">
                        <img src={this.state.img} width="100px" height="100px" alt="invalid image"/>

                    </div>
                    <div className="col-md-2 displayresult">

                            <div>{this.state.res}</div>
                    </div>
                </div>

      </div>

    );
    }
}

export default VApiPage;
class VApiPage扩展了React.Component{
建造师(道具){
超级(道具);
this.\u path=this.\u path.bind(this);
这个州={
国旗:1,,
路径:“”,
结果:“,
img:“
}
}
_路径(e){
这是我的国家({
路径:e.target.value
});
}
_结果(){
让img1=this.state.path;
让str1;
让str;
this.setState({img:img1});
str=”http://0.0.0.0:4000/“+str1+”/“+this.state.path;
取(str{
方法:“张贴”,
标题:{
“访问控制允许来源”:“*”
},
})
.then(res=>res.json())
。然后(res=>{
if(window.location.pathname.split(“/”[4]=“性别”){
这是我的国家({
res:res.性别
});
}
else if(window.location.pathname.split(“/”[4]=“情感”){
这是我的国家({
res:res.情感
});
}
});
}
render(){
返回(
{console.log(e.target.files[0].name);
this.setState({path:e.target.files[0].name,
img:e.target.files[0].name});}}/>
这个。_path(e)}占位符=“cols=”100“rows=”1“>
这个。_results()}>
分析
{this.state.res}
);
}
}
导出默认VApiPage;

您可能会收到一条非常清晰的错误消息,该消息可能重复。您的CORS设置不正确。这个问题已经被回答了很多次,对您的错误进行简单的google/stack overflow搜索会得到很多已经解决的结果。我不同意,这是一个python flask问题,应该有一个专门的答案。我个人正在寻找一个解决方案,如何将正确的参数传递给flask cors,以避免错误。如果您收到一条非常清晰的错误消息,则可能会出现重复的错误。您的CORS设置不正确。这个问题已经被回答了很多次,对您的错误进行简单的google/stack overflow搜索会得到很多已经解决的结果。我不同意,这是一个python flask问题,应该有一个专门的答案。我个人正在寻找一个解决方案,如何将正确的参数传递给flask cors,以避免该错误