解决Python调用Google My Business API的google.auth.transport.rest缺失错误
解决方案
1. 修正导入语句(优先尝试)
google.auth.transport.rest.AuthorizedSession 是基于httplib2的实现,如果你使用的是requests库,正确的导入路径应该是从google.auth.transport.requests中获取AuthorizedSession,修改代码开头为:
import google.auth from google.auth.transport.requests import Request, AuthorizedSession
2. 重新安装完整依赖包
如果坚持使用rest模块,先卸载现有冲突包,再安装完整依赖:
pip uninstall -y google google-auth google-auth-oauthlib pip install google-auth google-auth-oauthlib google-auth-httplib2
3. 确认Python环境一致性
确保运行代码的Python环境与pip安装的环境一致:
- 若使用Python3,对应使用
pip3安装:
pip3 install google-auth google-auth-oauthlib google-auth-httplib2
- 查看当前Python解释器路径:
which python # 或 which python3
- 查看pip对应的Python路径:
pip --version # 或 pip3 --version
确保两者路径匹配。
内容的提问来源于stack exchange,提问作者ertugrulozturk
相关产品推荐
相关产品推荐

