问题
I am using YouTube API to get the data and for a month there is an error when I try to make a request on a Windows Server 2012 R2, (local works).
Basically, before the script makes a request he updates a YouTube token in order not to perform a log on into Google Account. The function loads a pickle file with the credentials and updates them if necessary. The error happens on the line "creds.refresh(Request())" by drilling down by scopes-
def main_load_page(youtube, API_VERSION, SCOPES, CLIENT_SECRET, CHANNEL_ID):
# load token from pickle file, to avoid manual log in into a google account
TOKEN_FILE = 'client_secret_rhenus_oauth.pickle' # in the directory with the code
creds = None
if os.path.exists(TOKEN_FILE):
with open(TOKEN_FILE, 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request()) # here it throws the error
else:
flow = InstalledAppFlow.from_client_secrets_file(
CLIENT_SECRET, SCOPES)
creds = flow.run_local_server()
with open(TOKEN_FILE, 'wb') as token:
pickle.dump(creds, token)
return build(youtube, API_VERSION, credentials=creds, cache_discovery=False)
Here is the error:
google.auth.exceptions.RefreshError: ('invalid_scope: Some requested scopes were invalid. {invalid=[a, c, d, e, g, h, i, l, m, -, ., n, /, o, p, r, s, t, u, w, y, :]}', '{\n "error": "invalid_scope",\n "error_description": "Some requested scopes were invalid. {invalid\\u003d[a, c, d, e, g, h, i, l, m, -, ., n, /, o, p, r, s, t, u, w, y, :]}",\n "error_uri": "http://code.google.com/apis/accounts/docs/OAuth2.html"\n}')
It looks like the server changes scopes, which are "https://www.googleapis.com/auth/yt-analytics.readonly".
If someone has dealt with the same error will appreciate any help, while googling did not help really
来源:https://stackoverflow.com/questions/62299760/why-youtube-api-scopes-error-happens-on-the-windows-server