Why YouTube API Scopes error happens on the Windows Server?

有些话、适合烂在心里 提交于 2020-06-23 16:00:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!