当我将 freezegun 与 google storage api 一起使用时,出现以下错误。
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.'})
我认为忽略包可能会解决问题。参考:https ://github.com/spulec/freezegun/pull/185
有时需要忽略特定包(即库)的 FreezeGun 行为。一次调用可以忽略它们:
我尝试在忽略列表中添加 ["google", "google.auth", "google.cloud"],但仍然遇到相同的错误。
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()))
我对如何正确使用忽略包感到困惑。例如:
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)
无论我是否将 urllib3 添加到忽略列表,它仍然会引发SystemTimeWarning: System time is way off (before 2020-07-01). This will probably lead to SSL verification errors