Starting MongoDB with this connection string mongodb://mongo-service:27017 is giving me this error.
The issue only happens for me when running on Kubernetes. Localhost is working fine.
ERROR:src.app:Exception on /api/polls [GET]
Traceback (most recent call last):
File "/.venv/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "/.venv/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/.venv/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "/.venv/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/home/appuser/src/app.py", line 28, in get_all
polls = list(repository.get_all_polls())
File "/home/appuser/src/repository.py", line 11, in get_all_polls
return _get_collection().find()
File "/home/appuser/src/repository.py", line 28, in _get_collection
return mongo.get_collection(DATABASE, COLLECTION)
File "/home/appuser/src/mongo.py", line 15, in get_collection
return MongoClient(connection_string).get_database(database).get_collection(collection)
File "/.venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 704, in __init__
res = uri_parser.parse_uri(
File "/.venv/lib/python3.10/site-packages/pymongo/uri_parser.py", line 568, in parse_uri
nodes = split_hosts(hosts, default_port=default_port)
File "/.venv/lib/python3.10/site-packages/pymongo/uri_parser.py", line 376, in split_hosts
nodes.append(parse_host(entity, port))
File "/.venv/lib/python3.10/site-packages/pymongo/uri_parser.py", line 137, in parse_host
raise ValueError("Port must be an integer between 0 and 65535: %s" % (port,))
ValueError: Port must be an integer between 0 and 65535: 27017
I couldn't find the reason in the docs.