(debug)=
exclamation-circle TroubleshootingHere are a few tips for avoiding and debugging some common problems.
pip install -U requests-cacheDebug logging can be enabled with the standard python logging module, for example with {py:func}logging.basicConfig:
import logging logging.basicConfig(level='DEBUG')
For prettier, more readable logs, try the rich library's logging handler:
import logging from rich.logging import RichHandler logging.basicConfig( level='DEBUG', format="%(message)s", datefmt="[%X]", handlers=[RichHandler()] )
If you have other libraries installed with verbose debug logging, you can configure only the loggers you want with logger.setLevel():
import logging logging.basicConfig(level='WARNING') logging.getLogger('requests_cache').setLevel('DEBUG')
monkeypatch-issues for notes specific to {py:func}.install_cacherequests_cache package:from requests_cache import x
custom-serializers and {ref}custom-matching. In these cases, the easiest way to resolve the issue is to clear the cache with {py:meth}CachedSession.cache.clear() <.BaseCache.clear>.requests, urllib3 or requests-cache itself can potentially change response data, and be incompatible with previously cached responses. See issues #56 and #102.A cached response that can't be reused will simply be deleted and fetched again. If you get a traceback just by reading from the cache, this is **not** intended behavior, so please create a bug report!
Here are some error messages you may see either in the logs or (more rarely) in a traceback:
Unable to deserialize response with key {cache key}: This usually means that a response was previously cached in a format that isn't compatible with the current version of requests-cache or one of its dependencies. It could also be the result of switching {ref}serializers.~.BaseCache.clear the cache or {py:meth}~.BaseCache.remove_expired_responses to get rid of the invalid responses.Request for URL {url} failed; using cached response: This is just a notification that the {ref}stale_if_error <request-errors> option is working as intended~requests.RequestException: These are general request errors not specific to requests-cache. See requests documentation on Errors and Exceptions for more details.ModuleNotFoundError: No module named 'requests_cache.core': This module was deprecated in v0.6 and removed in v0.8. Just import from requests_cache instead of requests_cache.core.ImportError: Indicates a missing required or optional dependency.requirements for detailssqlite3.OperationalError: unable to open database file or {py:exc}IOError: This usually indicates a file permissions or ownership issue with either the database file or its parent directory.sqlite3.OperationalError: database is locked: This indicates a concurrency issue, and likely a bug. requests-cache + SQLite is intended to be thread-safe and multiprocess-safe, so please create a bug report if you encounter this.ResourceWarning: unclosed <ssl.SSLSocket ...>: This warning can safely be ignored.requests.Session, which uses connection pooling for better performance. In other words, these connections are intentionally left open to reduce the number of round-trips required for consecutive requests. For more details, see the following issues:import warnings warnings.simplefilter('ignore', ResourceWarning)
If you believe you‘ve found a bug, or if you’re just having trouble getting requests-cache to work the way you want, please create an issue for it on GitHub.
Details that will help your issue get resolved: