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/”, line 443, in _run_script

exec(code, module.__dict__)

File “/app/mongostreamapp/”, line 123, in

list_cursor = list(all_records)

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

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

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

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

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

return self.__start_session(True, causal_consistency=False)

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


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


File “/home/appuser/venv/lib/python3.7/site-packages/pymongo/”, 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/”, 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.


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.

1 Like