На запрашиваемом питоне ресурса отсутствует заголовок "Access-Control-Allow-Origin"
Когда этот API(на размещенном сервере) вызывает интерфейс, он перенаправляет на Google OAuth для входа в Google в то время, когда появляется эта ошибка.
Доступ к выборке можно получить по адресу https: //accounts.google.com/o/oauth2/auth? response_type= code&client_id=114887XXXXX7-rsXXXXXXXXXXXXXXXXXXXXXXXXXXrg.apps.googleusercontent.com&redirect_uri= https% 3backttF0-2FFF2F2F2F2_F2_F2_F2_F2_F2_F2_F2_F2_F2_F2_F2_F2 ...... . 'был заблокирован политикой CORS: Ответ на предварительный запрос не проходит проверку контроля доступа: в запрошенном ресурсе отсутствует заголовок'Access-Control-Allow-Origin'. Если непрозрачный ответ отвечает вашим потребностям, установите режим запроса "no-cors", чтобы получить ресурс с отключенным CORS.
Среда, которую я использую:
Backend - Python
Front End - реагирование
Веб- сервис r- WEBHOSTPYTHON
Здесь я добавляю код на стороне сервера для 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