You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
requests_cache/session.py:103: ingetreturnself.request('GET', url, params=params, **kwargs)
requests_cache/session.py:159: inrequestreturnsuper().request(method, url, *args, headers=headers, **kwargs) # type: ignore
.venv/lib/python3.7/site-packages/requests/sessions.py:589: inrequestresp=self.send(prep, **send_kwargs)
requests_cache/session.py:195: insendactions.update_from_cached_response(cached_response, self.cache.create_key, **kwargs)
requests_cache/policy/actions.py:194: inupdate_from_cached_responseelifcreate_keyandnotself._validate_vary(cached_response, create_key, **key_kwargs):
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self=CacheActions(expire_after=-1)
cached_response=CachedResponse(_content=b'mock redirect response with Vary header (2/2)', created_at='2023-06-05 17:56:56.815238', ela.../requests-cache.com/vary-redirect-target'), status_code=200, url='http+mock://requests-cache.com/vary-redirect-target')
create_key=<boundmethodBaseCache.create_keyof<SQLiteCache(name=/tmp/pytest-of-runner/pytest-0/popen-gw1/test_match_headers__vary_with_4/24501901-26eb-4b6b-a6d0-6b12df83c48b.db)>>key_kwargs= {'allow_redirects': True, 'cert': None, 'match_headers': ['Accept-Language'], 'proxies': OrderedDict(), ...}
vary='Accept-Language'def_validate_vary(
self, cached_response: 'CachedResponse', create_key: KeyCallback, **key_kwargs
) ->bool:
"""If the cached response contains Vary, check that the specified request headers match"""vary=cached_response.headers.get('Vary')
ifnotvary:
returnTrueelifvary=='*':
returnFalse# Generate a secondary cache key based on Vary for both the cached request and new request.# If there are redirects, compare the new request against the last request in the chain.key_kwargs['match_headers'] = [k.strip() forkinvary.split(',')]
vary_request= (
cached_response.history[-1].request>ifcached_response.historyelsecached_response.request
)
EAttributeError: 'dict'objecthasnoattribute'request'requests_cache/policy/actions.py:308: AttributeError
CachedResponse.history should contain CachedResponse when there is redirect history available. Instead, it contains dicts, meaning the structure hook is not working.
The text was updated successfully, but these errors were encountered:
It turns out that CachedResponse.history wasn't being fully deserialized on python<=3.8 due to an unevaluated ForwardRef, causing the cattrs unstructure hook to fail.
When not yet evaluated, ForwardRef.__forward_value__ is None, so this call:
converter.structure(obj, cls.__forward_value__)
no longer works.
I'm unsure why this behaves differently on python 3.9+. Anyway, the workaround is to manually evaluate the ForwardRef:
JWCook
changed the title
CachedResponse.history contains dicts instead of CachedResponse objects on python 3.7 and 3.8
CachedResponse.history is not fully deserialized on python 3.7 and 3.8
Jun 5, 2023
Found during #835; related to python-attrs/cattrs#206
Example error:
CachedResponse.history
should containCachedResponse
when there is redirect history available. Instead, it contains dicts, meaning the structure hook is not working.The text was updated successfully, but these errors were encountered: