Python GmailAPI OAuth2在请求转到SSH服务器连接上的URL时出现问题

Python GmailAPI OAuth2在请求转到SSH服务器连接上的URL时出现问题,python,oauth-2.0,google-api,gmail-api,Python,Oauth 2.0,Google Api,Gmail Api,我正在使用默认的如何从谷歌设置Gmail API 我已经在控制台中设置了一个oAuth2键,当我运行python脚本时,它将被激活 当我在终端中运行代码时,我会得到URL,并将其复制到本地机器上的web浏览器中。 我进入oAuth屏幕并批准该应用程序 然后它重定向到localhost:13949,并说那里没有网页。python脚本只是挂在那里,好像什么都没发生过 我不知道该怎么解决这个问题 """Shows basic usage of the Gmail API. Lists

我正在使用默认的如何从谷歌设置Gmail API

我已经在控制台中设置了一个oAuth2键,当我运行python脚本时,它将被激活

当我在终端中运行代码时,我会得到URL,并将其复制到本地机器上的web浏览器中。 我进入oAuth屏幕并批准该应用程序

然后它重定向到localhost:13949,并说那里没有网页。python脚本只是挂在那里,好像什么都没发生过

我不知道该怎么解决这个问题

    """Shows basic usage of the Gmail API.
    Lists the user's Gmail labels.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('gmail', 'v1', credentials=creds)```

您的
credentials.json文件中有哪些重定向URI?您是否尝试重新下载凭据并再次运行?另外,您是否安装了所有必要的软件包?(运行
pip安装--升级google api python客户端google-auth-httplib2 google-auth oauthlib
)?这里也有同样的问题@RafaGuillermo,是的,我尝试了重新下载(甚至为gmail和其他api(如Drive)创建了新的下载),还重新安装了客户端。与BostonMacOSX描述的结果相同。你知道吗?你的
credentials.json
文件中有什么重定向URI?您是否尝试重新下载凭据并再次运行?另外,您是否安装了所有必要的软件包?(运行
pip安装--升级google api python客户端google-auth-httplib2 google-auth oauthlib
)?这里也有同样的问题@RafaGuillermo,是的,我尝试了重新下载(甚至为gmail和其他api(如Drive)创建了新的下载),还重新安装了客户端。与BostonMacOSX描述的结果相同。有什么想法吗?