Python 验证\u oauth2 \u令牌是否将对象用作函数

Python 验证\u oauth2 \u令牌是否将对象用作函数,python,google-authentication,Python,Google Authentication,我在那里使用后端进行google auth: 看起来有点过时,最奇怪的是有一行: idinfo = id_token.verify_oauth2_token(token, requests.Request(), CLIENT_ID) 在实现中,您可以看到,在嵌套函数调用中,相同的请求对象会到达: def _fetch_certs(request, certs_url): """Fetches certificates. Google-style cerificate endpoints r

我在那里使用后端进行google 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')
请求是一个对象,甚至文档也声称是这样,并将其用作函数。我得到的错误是:

TypeError:“请求”对象不可调用


应该更改哪些内容?

很可能您调用了错误的python请求库

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)
如果需要区分两个可用的请求库

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)

请参阅:

很可能您调用了错误的python请求库

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)
如果需要区分两个可用的请求库

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)
见: