Firebase Authentication: 'HTTPResponse' object has no attribute 'strict', status: error
Asked Answered
E

5

34

I'm a tad baffled as to why this bit of code has suddenly decided to fail when it had been working fine for a week.

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,""

The error message returned is: 'HTTPResponse' object has no attribute 'strict' And I can only replicate this error when I am testing on my cloud server as opposed to localhost.

I have reviewed the stack trace and I see it is the auth.verify_id_token function causing issues, and specifically then:

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'

EDIT:

Ok so Patrick below pointed me to a link that tells me:

"this appears to be an incompatibility in cachecontrol with the new release of urllib3 2.0. strict is no longer a supported argument on the HTTPResponse class. For the time being you'll likely need to pin to an older version of urllib3 or work with the cachecontrol team to update their usage."

I'll have to see if I can do anything about this for now. For example using urllib3 2.0.0 as a workaround as suggested by Patrick.

Elan answered 4/5, 2023 at 16:23 Comment(0)
T
23

Looks like you're hitting this bug:

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

There is no fix posted so far.

Per the https://urllib3.readthedocs.io/en/stable/changelog.html#deprecated changelog, using 1.26.15 "fixed" this for me. [Edited: said to try using urllib3 2.0.0 as a workaround, but that did not work.]

Tiki answered 4/5, 2023 at 17:24 Comment(4)
I added more details and a workaround. I'm trying to use the workaround: I'm using a docker image starting with python:3.9-slim-bullseye, and so far haven't figured out a good way to use urllib3 2.0.0Tiki
Oh man. Thanks @PatrickMansfield - I've been dissecting my code apart to try and figure out what was causing it. At least now I know it's not me. I'll edit my question to provide people with a bit more info from what I'm seeing in the link.Elan
This was caused by firebase-admin -> requests -> urllib3 in my case. Problem is that requests require Any version of urllib. Workaround for me was to add a urllib3<2.0.0 in the requirements-fileBenz
For me it worked after running this command pipenv install urllib3==1.26.15Ellswerth
A
16

I encountered the same error, likely due to the same underlying cause, when running poetry install. This won't help OP, but in case anyone else finds this post for the same reason, I was able to get around it by upgrading from poetry 1.1.14 to 1.3.2.

Arrogance answered 4/5, 2023 at 19:8 Comment(2)
Context: github.com/python-poetry/poetry/issues/7877Parfait
Thanks - setting urllib3 worked me but I ended up using this workaround too as I'm using poetry, was already setting a version for it, updating it is a good idea, and it means there is one less version to set. Oddly, I looked and poetry changed to use urllib3 at version to 1.26.0 to get a newer version (they could have probably should have used >= some-version), but that also means it won't use a version newer than 1.26.0. Quite the version heck.Tiki
D
4

I encountered same problem while building a docker image for a Django project. Mine was happening on both local and on digital ocean. I simply changed my installed poetry version from 1.1.8 to 1.4.2 and the problem disappeared.

Dulse answered 6/5, 2023 at 0:55 Comment(1)
I already have poetry version 1.4.2 and urllib3 (1.26.8) but still getting error - 'HTTPResponse' object has no attribute 'strict'. Any idea why its still failing ?Janessa
K
1

I tried different variations, but what helped me was changing the version of poetry from 1.1.13 to 1.3.2 and also changing the urllib3 version in poetry.lock on ">=1.26.1, <2.0.0".

Killjoy answered 10/5, 2023 at 13:27 Comment(0)
S
1

I upgraded to 1.2.2 which was one of the closest versions of my dependency and it worked perfectly.

Stumpf answered 31/5, 2023 at 20:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.