"InstalledAppFlow.run\本地\服务器()“系统地在重定向URL的末尾添加斜杠

2024-05-16 19:48:35 发布

您现在位置:Python中文网/ 问答频道 /正文

代码如下:

from typing import List
from google_auth_oauthlib.flow import InstalledAppFlow

PATH_FILE_SECRETS: str = secrets.json'
SCOPES: List[str] = ['https://www.googleapis.com/auth/gmail.readonly']
LOCAL_REDIRECT_SERVER_DOMAIN='thermotest.ddns.net'
LOCAL_REDIRECT_SERVER_PORT=80

flow: InstalledAppFlow = InstalledAppFlow.from_client_secrets_file(PATH_FILE_SECRETS, SCOPES)

credentials = flow.run_local_server(LOCAL_REDIRECT_SERVER_DOMAIN, LOCAL_REDIRECT_SERVER_PORT)

我使用google-auth-oauthlib版本0.2.0(the last version)。你知道吗

我已经注册了这个重定向URL:

http://thermotest.ddns.net:80   

问题是方法“run_local_server”生成一个以斜杠结尾的URL:

 ...&redirect_uri=http%3A%2F%2Fthermotest.ddns.net%3A80%2F...

一旦解码,就会得到:

 http://thermotest.ddns.net:80/

因此,谷歌抱怨说:

The redirect URI in the request, http://thermotest.ddns.net:80/, does not match the ones authorized for the OAuth client.

这是正常的,因为“http://thermotest.ddns.net:80/”与“http://thermotest.ddns.net:80”不完全相同。你知道吗

如果我通过删除最后一个“%2F”(我删除最后一个斜杠)来修改URL,那么就可以了。你知道吗

我的问题是:为什么“run_local_server”系统地在重定向URL的末尾添加斜杠?我能告诉方法不要这样做吗?你知道吗


Tags: therunfromauthhttpurlnetserver