Firebase 身份验证:“HTTPResponse”对象没有属性“strict”,状态:错误

use*_*806 34 flask firebase firebase-admin

我有点困惑为什么这段代码在已经正常工作一周的情况下突然决定失败。

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,""
Run Code Online (Sandbox Code Playgroud)

返回的错误消息是:“HTTPResponse”对象没有“strict”属性并且当我在云服务器而不是本地主机上进行测试时,我只能复制此错误。

我查看了堆栈跟踪,发现这是auth.verify_id_token导致问题的函数,具体来说:

ile "/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'
Run Code Online (Sandbox Code Playgroud)

编辑:

好吧,帕特里克下面给我指出了一个链接,告诉我:

“这似乎是缓存控制与新版本的 urllib3 2.0 不兼容。strict 不再是 HTTPResponse 类上受支持的参数。目前,您可能需要固定到旧版本的 urllib3 或使用缓存控制团队更新他们的使用情况。”

我得看看现在我能不能做点什么。例如,按照帕特里克的建议,使用 urllib3 2.0.0 作为解决方法。

Pat*_*eld 23

看来您遇到了这个错误:

https://github.com/ionrock/cachecontrol/issues/292

到目前为止还没有发布任何修复程序。

根据https://urllib3.readthedocs.io/en/stable/changelog.html#deprecated变更日志,使用 1.26.15 “修复”了这个问题。[编辑:据说尝试使用 urllib3 2.0.0 作为解决方法,但这不起作用。]

  • 对我来说,运行此命令“pipenv install urllib3==1.26.15”后它起作用了 (2认同)

bsa*_*uce 16

运行时,我遇到了相同的错误,可能是由于相同的根本原因poetry install。这对OP没有帮助,但如果其他人出于同样的原因找到这篇文章,我可以通过从诗歌 1.1.14 升级到 1.3.2 来解决它。

  • 上下文:https://github.com/python-poetry/poetry/issues/7877 (2认同)