Monday, 6 September 2021

How to use Ignore packages in freezegun?

While I use freezegun with google storage api, I got the following error.

google.auth.exceptions.RefreshError: ('invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.', {'error': 'invalid_grant', 'error_description': 'Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.'})

I think ignore packages may solve the problem. Ref: https://github.com/spulec/freezegun/pull/185

Sometimes it's desired to ignore FreezeGun behaviour for particular packages (i.e. libraries). It's possible to ignore them for a single invocation:

I tried add ["google", "google.auth", "google.cloud"] in ignore list, but still got the same error.

from google.cloud import storage
import freezegun

ig_ms = ["google", "google.oauth2", "urllib3", "google.cloud"]
freezegun.configure(extend_ignore_list=ig_ms)


with freezegun.freeze_time("2017-05-21", ignore=ig_ms):
    client = storage.Client()

    print(list(client.list_buckets()))

I am confused about how to use Ignore Packages correctly. For example:

import urllib3
import freezegun

with freezegun.freeze_time("2017-05-21", ignore=['urllib3']):
    http = urllib3.PoolManager()
    resp = http.request("GET", "https://httpbin.org/robots.txt")
    print(resp.status)

whether I add urllib3 to ignore list or not, it will still raise SystemTimeWarning: System time is way off (before 2020-07-01). This will probably lead to SSL verification errors



from How to use Ignore packages in freezegun?

No comments:

Post a Comment