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.

Reddspark
  • 6,934
  • 9
  • 47
  • 64

5 Answers5

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.]

  • 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.0 – Patrick Mansfield May 04 '23 at 18:03
  • 1
    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. – Reddspark May 04 '23 at 18:23
  • 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-file – Blip May 05 '23 at 12:25
  • 1
    For me it worked after running this command `pipenv install urllib3==1.26.15` – Ali Hussnain - alichampion Jun 08 '23 at 09:37
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.

bsauce
  • 624
  • 4
  • 12
  • 2
    Context: https://github.com/python-poetry/poetry/issues/7877 – tzachs May 04 '23 at 22:10
  • 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. – Patrick Mansfield May 06 '23 at 14:16
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.

chidimo
  • 2,684
  • 3
  • 32
  • 47
  • 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 ? – Harvindar Singh Garcha May 26 '23 at 11:49
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".

Nikita
  • 11
  • 1
1

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