Error when deploying app using Flask as backend

Hello, I’m trying to deploy a ML dashboard, which I’ve built with Flask as backend framework and Streamlit as frontend framework. First, I was getting an error referring to the package I was using for MySQL connection, so I switched it to ‘pymysql’. But now, I’m getting a huge chunk of logs.

Link to app: Dashboard ShriMP · Streamlit (dashboard-shrimp-ml.streamlit.app)
Link to repo: NoeliaIntriago/MI-Sector-Acuicola (github.com)

Log:

Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/cache_utils.py”, line 264, in _get_or_create_cached_value
cached_result = cache.read_result(value_key)
File “/home/adminuser/venv/lib/python3.9/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: Key not found in disk cache

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/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.9/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.9/site-packages/streamlit/runtime/caching/storage/local_disk_cache_storage.py”, line 145, in get
with streamlit_read(path, binary=True) as input:
File “/usr/local/lib/python3.9/contextlib.py”, line 119, in enter
return next(self.gen)
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/file_util.py”, line 77, in streamlit_read
if os.stat(filename).st_size == 0:
FileNotFoundError: [Errno 2] No such file or directory: ‘/home/appuser/.streamlit/cache/e246d1c0afe606994a80a799452b578e-d41d8cd98f00b204e9800998ecf8427e.memo’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/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.9/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.9/site-packages/streamlit/runtime/caching/storage/local_disk_cache_storage.py”, line 150, in get
raise CacheStorageKeyNotFoundError(“Key not found in disk cache”)
streamlit.runtime.caching.storage.cache_storage_protocol.CacheStorageKeyNotFoundError: Key not found in disk cache

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

Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/cache_utils.py”, line 312, in _handle_cache_miss
cached_result = cache.read_result(value_key)
File “/home/adminuser/venv/lib/python3.9/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: Key not found in disk cache

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/connection.py”, line 203, in _new_conn
sock = connection.create_connection(
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/util/connection.py”, line 85, in create_connection
raise err
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/util/connection.py”, line 73, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

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

Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/connectionpool.py”, line 790, in urlopen
response = self._make_request(
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/connectionpool.py”, line 496, in _make_request
conn.request(
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/connection.py”, line 395, in request
self.endheaders()
File “/usr/local/lib/python3.9/http/client.py”, line 1280, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File “/usr/local/lib/python3.9/http/client.py”, line 1040, in _send_output
self.send(msg)
File “/usr/local/lib/python3.9/http/client.py”, line 980, in send
self.connect()
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/connection.py”, line 243, in connect
self.sock = self._new_conn()
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/connection.py”, line 218, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fbb4c26b820>: Failed to establish a new connection: [Errno 111] Connection refused

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

Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/site-packages/requests/adapters.py”, line 486, in send
resp = conn.urlopen(
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/connectionpool.py”, line 844, in urlopen
retries = retries.increment(
File “/home/adminuser/venv/lib/python3.9/site-packages/urllib3/util/retry.py”, line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘127.0.0.1’, port=5000): Max retries exceeded with url: /api/clients (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7fbb4c26b820>: Failed to establish a new connection: [Errno 111] Connection refused’))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 534, in _run_script
exec(code, module.dict)
File “/mount/src/mi-sector-acuicola/frontend/dashboard.py”, line 170, in
main()
File “/mount/src/mi-sector-acuicola/frontend/dashboard.py”, line 157, in main
get_clients(),
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/cache_utils.py”, line 212, in wrapper
return cached_func(*args, **kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/cache_utils.py”, line 241, in call
return self._get_or_create_cached_value(args, kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/cache_utils.py”, line 267, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/cache_utils.py”, line 321, in _handle_cache_miss
computed_value = self._info.func(*func_args, **func_kwargs)
File “/mount/src/mi-sector-acuicola/frontend/dashboard.py”, line 16, in get_clients
response = requests.get(‘http://127.0.0.1:5000/api/clients’)
File “/home/adminuser/venv/lib/python3.9/site-packages/requests/api.py”, line 73, in get
return request(“get”, url, params=params, **kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/requests/api.py”, line 59, in request
return session.request(method=method, url=url, **kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/requests/sessions.py”, line 589, in request
resp = self.send(prep, **send_kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/requests/sessions.py”, line 703, in send
r = adapter.send(request, **kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/requests/adapters.py”, line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘127.0.0.1’, port=5000): Max retries exceeded with url: /api/clients (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7fbb4c26b820>: Failed to establish a new connection: [Errno 111] Connection refused’))
2024-01-08 22:14:40.919 503 GET /script-health-check (10.13.78.38) 558.55ms

Streamlit v1.28.2, Python v3.11
Any help will be apreciated

Sad to hear that, is there a way I can handle requests from another file? For example:
root
|—backend/api.py
|—frontend
|—|—dashboard.py
|—|—style.css

So when I need to make a request, I call the function from backend/api.py, or do they need to be on the same file? Obviously, both backend and frontend now working on streamlit

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