streamlit.runtime.caching.storage.cache_storage_protocol.CacheStorageKeyNotFoundError: Key not found in mem cache

Hello, I’m having a caché error while deploying to streamlit an app using selenium, locally it works and deployed sometimes it works and sometimes dont, for me it’s hard to reproduce and debug this locally. This are the logs:

2023-10-01 15:57:33.626 Uncaught app exception

Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py", line 87, in get

    entry_bytes = self._read_from_mem_cache(key)

                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py", line 137, in _read_from_mem_cache

    raise CacheStorageKeyNotFoundError("Key not found in mem cache")

streamlit.runtime.caching.storage.cache_storage_protocol.CacheStorageKeyNotFoundError: Key not found in mem cache


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_data_api.py", line 634, in read_result

    pickled_entry = self.storage.get(key)

                    ^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py", line 89, in get

    entry_bytes = self._persist_storage.get(key)

                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/storage/local_disk_cache_storage.py", line 155, in get

    raise CacheStorageKeyNotFoundError(

streamlit.runtime.caching.storage.cache_storage_protocol.CacheStorageKeyNotFoundError: Local disk cache storage is disabled (persist=None)


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 263, in _get_or_create_cached_value

    cached_result = cache.read_result(value_key)

                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_data_api.py", line 636, in read_result

    raise CacheKeyNotFoundError(str(e)) from e

streamlit.runtime.caching.cache_errors.CacheKeyNotFoundError: Local disk cache storage is disabled (persist=None)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py", line 87, in get

    entry_bytes = self._read_from_mem_cache(key)

                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py", line 137, in _read_from_mem_cache

    raise CacheStorageKeyNotFoundError("Key not found in mem cache")

streamlit.runtime.caching.storage.cache_storage_protocol.CacheStorageKeyNotFoundError: Key not found in mem cache


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_data_api.py", line 634, in read_result

    pickled_entry = self.storage.get(key)

                    ^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py", line 89, in get

    entry_bytes = self._persist_storage.get(key)

                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/storage/local_disk_cache_storage.py", line 155, in get

    raise CacheStorageKeyNotFoundError(

streamlit.runtime.caching.storage.cache_storage_protocol.CacheStorageKeyNotFoundError: Local disk cache storage is disabled (persist=None)


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 311, in _handle_cache_miss

    cached_result = cache.read_result(value_key)

                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_data_api.py", line 636, in read_result

    raise CacheKeyNotFoundError(str(e)) from e

streamlit.runtime.caching.cache_errors.CacheKeyNotFoundError: Local disk cache storage is disabled (persist=None)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 541, in _run_script

    exec(code, module.__dict__)

  File "/mount/src/wavefinder/table_windguru.py", line 5, in <module>

    plot_forecast_as_table(WINDGURU_URLS)

  File "/mount/src/wavefinder/front/one/table.py", line 132, in plot_forecast_as_table

    initial_forecast = load_forecast(urls)

                       ^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 211, in wrapper

    return cached_func(*args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 240, in __call__

    return self._get_or_create_cached_value(args, kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 266, in _get_or_create_cached_value

    return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 320, in _handle_cache_miss

    computed_value = self._info.func(*func_args, **func_kwargs)

                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/mount/src/wavefinder/front/one/table.py", line 72, in load_forecast

    df = multithread.scrape_multiple_browser(urls, Windguru())

         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/mount/src/wavefinder/multi/multithread.py", line 13, in scrape_multiple_browser

    results.append(object.scrape(browser, url, index))

                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/mount/src/wavefinder/scrapers/windguru.py", line 167, in scrape

    return self.process_soup(soup, url, index)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/mount/src/wavefinder/scrapers/windguru.py", line 106, in process_soup

    df = self.get_dataframe_from_soup(soup, url, index)

         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/mount/src/wavefinder/scrapers/windguru.py", line 101, in get_dataframe_from_soup

    forecast["spot_name"] = self.parse_spot_names(soup, total_records)

                                                  ^^^^

UnboundLocalError: cannot access local variable 'total_records' where it is not associated with a value

This is my app url:

this is my app github repo:

All help would be appreciated

At least a part of the problem lies here:

try:
    total_records = len(max(forecast.items(), key=lambda item: len(item[1]))[1])
except Exception as e:
    st.write("QUEEE FUEE")
    st.write(url)
    st.write(index)
forecast["spot_name"] = self.parse_spot_names(soup, total_records)

Eating exceptions like that will make you have a lot of fun trying to debug issues where the try part fails. Besides, total_records is undefined when that happens, causing even more issues.

I think for some reason the selenium (through a browser) sometimes does not load the page correctly, and forecast is an empty dictionary, so when the forecast is empty i’ll put total_records = 0, while I try to debug why the browser does not render correctly the page.
Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.