Error during deployment

I’m new to data science and using streamlit. I wrote my script and it worked fine in localhost streamlit. Unfortunately, when I deployed to streamlit web, it there is an error. I tried to look for solutions but no success.

here is the error

Traceback (most recent call last):

File “/home/appuser/venv/lib/python3.7/site-packages/streamlit/scriptrunner/script_runner.py”, line 443, in _run_script

exec(code, module.__dict__)

File “/app/mongostreamapp/agazi.py”, line 123, in

list_cursor = list(all_records)

File “/home/appuser/venv/lib/python3.7/site-packages/pymongo/cursor.py”, line 1248, in next

if len(self.__data) or self._refresh():

File “/home/appuser/venv/lib/python3.7/site-packages/pymongo/cursor.py”, line 1139, in _refresh

self.__session = self.__collection.database.client._ensure_session()

File “/home/appuser/venv/lib/python3.7/site-packages/pymongo/mongo_client.py”, line 1663, in _ensure_session

return self.__start_session(True, causal_consistency=False)

File “/home/appuser/venv/lib/python3.7/site-packages/pymongo/mongo_client.py”, line 1608, in __start_session

self._topology._check_implicit_session_support()

File “/home/appuser/venv/lib/python3.7/site-packages/pymongo/topology.py”, line 519, in _check_implicit_session_support

self._check_session_support()

File “/home/appuser/venv/lib/python3.7/site-packages/pymongo/topology.py”, line 536, in _check_session_support

readable_server_selector, self._settings.server_selection_timeout, None

File “/home/appuser/venv/lib/python3.7/site-packages/pymongo/topology.py”, line 229, in _select_servers_loop

% (self._error_message(selector), timeout, self.description)

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused, Timeout: 30s, Topology Description: <TopologyDescription id: 62739111470fd455e99343de, topology_type: Unknown, servers: [<ServerDescription (‘localhost’, 27017) server_type: Unknown, rtt: None, error=AutoReconnect(‘localhost:27017: [Errno 111] Connection refused’)>]>

I appreciate your kind help.

Thanks,
Tess

Can you share a link to your github repo?
I assume you are trying to access a mongodb database on localhost? If you run streamlit on streamlit cloud, there is no mongodb database anymore.

Hello Franky1,

Yes, you are right. I’m trying to access mongo db from a localhost. Here is my github

Thank you

As I said, this does not work that way on streamlit cloud. The streamlit app runs on the server instance and does not find a MongoDB database on localhost because it does not exist there.
You need to rethink your approach. One possibility would be to make your local MongoDB accessible from the outside or to run MongoDB on a server or hosted service as well.

1 Like

Ok, I will try to work. Thank you again !

Here is my first streamlit app deployed. Thank you for your kind help. It was very helpful.

https://share.streamlit.io/tessredie/mongostreamapp/agazi.py

1 Like

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