You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Auth报错:'HTTPResponse'无'strict'属性,仅云端环境复现

解决auth.verify_id_token引发的'HTTPResponse' object has no attribute 'strict'错误

问题场景

一段运行正常的Firebase身份验证代码突然在云端服务器失效,本地环境无异常:

import firebase_admin
from firebase_admin import firestore, credentials, db, auth

def userIsLoggedIn(self, id_token: str) -> bool:
    try:
        decoded_token = auth.verify_id_token(id_token)
        self.uid = decoded_token['uid']
    except Exception as e:
        return False, str(e)       
    
    return True, ""

报错信息:

'HTTPResponse' object has no attribute 'strict'

堆栈跟踪指向cachecontrol序列化模块:

File "/usr/local/lib/python3.11/site-packages/cachecontrol/serialize.py", line 54, in dumps
2023-05-04T16:11:04.767062340Z u"strict": response.strict,
2023-05-04T16:11:04.767067540Z ^^^^^^^^^^^^^^^
2023-05-04T16:11:04.767072540Z AttributeError: 'HTTPResponse' object has no attribute 'strict'

根因分析

这是cachecontrol与urllib3 2.0+版本的兼容性问题:urllib3 2.0对HTTPResponse类做了改动,移除了strict属性,但旧版本的cachecontrol仍在代码中引用该属性,导致调用auth.verify_id_token时触发异常。

解决方案

  • 临时降级urllib3到兼容版本
    执行命令固定urllib3为1.x系列的稳定版本:
    pip install urllib3==1.26.15
    
  • 等待cachecontrol官方适配
    关注cachecontrol的版本更新,待其发布支持urllib3 2.0的版本后,直接升级cachecontrol即可:
    pip install --upgrade cachecontrol
    

注:不要尝试使用urllib3 2.0.0作为临时解决方法——问题正是由urllib3 2.0版本的改动引发的,降级到1.x版本才能彻底规避该兼容性问题。

内容的提问来源于stack exchange,提问作者Reddspark

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 19:13:32