Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 否';访问控制允许原点';请求的资源上存在标头_Python_Reactjs_Google Api_Youtube Data Api_Flask Cors - Fatal编程技术网

Python 否';访问控制允许原点';请求的资源上存在标头

Python 否';访问控制允许原点';请求的资源上存在标头,python,reactjs,google-api,youtube-data-api,flask-cors,Python,Reactjs,Google Api,Youtube Data Api,Flask Cors,当这个API(在托管服务器上)在前端调用时,它将重定向到GoogleOAuth,以便在出现此错误时进行Google登录 CORS策略已阻止从源“”在“”处(从“”重定向)获取的访问:对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许源”标头。如果不透明响应满足您的需要,请将请求的模式设置为“no cors”,以获取禁用cors的资源 我使用的环境是: 后端-Python 前端-reactjs webservicer-WEBHOSTPYTHON 在这里,我为goggle oAu

当这个API(在托管服务器上)在前端调用时,它将重定向到GoogleOAuth,以便在出现此错误时进行Google登录

CORS策略已阻止从源“”在“”处(从“”重定向)获取的访问:对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许源”标头。如果不透明响应满足您的需要,请将请求的模式设置为“no cors”,以获取禁用cors的资源

我使用的环境是:

后端-Python

前端-reactjs

webservicer-WEBHOSTPYTHON

在这里,我为goggle oAuthentication添加了服务器端代码

@app.route('/oauth2callback',methods=['GET', 'POST'])
@cross_origin(origins='*',allow_headers=['Access-Control-Allow- 
Origin'])
def oauth2callback():
    # Specify the state when creating the flow in the callback so that 
it can
    # verify the authorization server response.
    state = flask.session['state']
    flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
        CLIENT_SECRETS_FILE, scopes=SCOPES, state=state)

    flow.redirect_uri = flask.url_for('oauth2callback', 
_external=True)

    # Use the authorization server's response to fetch the OAuth 2.0 
tokens.
    authorization_response = flask.request.url
    #authorization_response = flask.request.headers['Access-Control- 
Allow-Origin'] = '*'
    authorization_response = flask.Response.headers.set['Access- 
Control-Allow-Origin'] = '*'
    authorization_response = authorization_response.replace('http', 
'https')
    client_secret = 'lDXXXXXXXXXXXXXXXXZoK'
    flow.fetch_token(client_secret=client_secret, 
authorization_response=authorization_response)

    # Store the credentials in the session.
    # ACTION ITEM for developers:
    #     Store user's access and refresh tokens in your data store if
    #     incorporating this code into your real app.
    credentials = flow.credentials
    flask.session['credentials'] = {
        'token': credentials.token,
        'refresh_token': credentials.refresh_token,
        'token_uri': credentials.token_uri,
        'client_id': credentials.client_id,
        'client_secret': credentials.client_secret,
        'scopes': credentials.scopes
    }
    data1=flask.redirect(flask.url_for('index'))
    data1.headers['Access-Control-Allow-Origin'] = '*'
    return data1 
获取错误时前端屏幕短