gpt4 book ai didi

python - verify_oauth2_token 使用对象作为函数

转载 作者:太空宇宙 更新时间:2023-11-03 20:16:54 26 4
gpt4 key购买 nike

我正在使用后端进行谷歌身份验证: https://developers.google.com/identity/sign-in/android/backend-auth

看起来有点过时了,最奇怪的是有一行:

idinfo = id_token.verify_oauth2_token(token, requests.Request(), CLIENT_ID)

在实现中,您可以看到在嵌套函数调用中,相同的请求对象到达那里:

def _fetch_certs(request, certs_url):
"""Fetches certificates.

Google-style cerificate endpoints return JSON in the format of
``{'key id': 'x509 certificate'}``.

Args:
request (google.auth.transport.Request): The object used to make
HTTP requests.
certs_url (str): The certificate endpoint URL.

Returns:
Mapping[str, str]: A mapping of public key ID to x.509 certificate
data.
"""
response = request(certs_url, method='GET')

request 是一个对象,甚至文档也声明如此,并将其用作函数。我得到的错误是:

TypeError: 'Request' object is not callable

那里应该改变什么?

最佳答案

很可能您调用了错误的 python requests 库。

如果您需要区分 2 个可用的请求库。

from google.auth.transport import requests as google_auth_request
import requests

req = google_auth_request.Request()

idinfo = id_token.verify_oauth2_token(token, req, CLIENT_ID)

参见:https://google-auth.readthedocs.io/en/latest/reference/google.oauth2.id_token.html

关于python - verify_oauth2_token 使用对象作为函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58396729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com