How to access Azure Cosmos mongoDB vcore cluster data via python
I am trying to access Cosmos MongoDB vcore cluster data in my python code. Cluster connection string is mentioned below. I am getting server timeout error. I would also like to know how to use mongdb REST API to read the data.
Connection String:
mongodb+srv://<username>:<password>@ghostxcosmoscluster.mongocluster.cosmos.azure.com?retrywrites=false&maxIdleTimeMS=120000&tls=true&authMechanism=SCRAM-SHA-256
Error details:
Traceback (most recent call last):
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\test.py", line 9, in <module>
databases = client.list_database_names()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\mongo_client.py", line 2196, in list_database_names
res = self._list_databases(session, nameOnly=True, comment=comment)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\mongo_client.py", line 2145, in _list_databases
res = admin._retryable_read_command(cmd, session=session, operation=_Op.LIST_DATABASES)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\database.py", line 1067, in _retryable_read_command
return self._client._retryable_read(_cmd, read_preference, session, operation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\mongo_client.py", line 1861, in _retryable_read
return self._retry_internal(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo_csot.py", line 119, in csot_wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\mongo_client.py", line 1828, in _retry_internal
).run()
^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\mongo_client.py", line 2565, in run
return self._read() if self._is_read else self._write()
^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\mongo_client.py", line 2700, in _read
self._server = self._get_server()
^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\mongo_client.py", line 2656, in _get_server
return self._client._select_server(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\mongo_client.py", line 1647, in _select_server
server = topology.select_server(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\topology.py", line 402, in select_server
server = self._select_server(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\topology.py", line 380, in _select_server
servers = self.select_servers(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\topology.py", line 287, in select_servers
server_descriptions = self._select_servers_loop(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\prhurakadli\OneDrive - Microsoft\Desktop\Multi Agent Test\env\Lib\site-packages\pymongo\synchronous\topology.py", line 337, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: label empty or too long, Timeout: 30s, Topology Description: <TopologyDescription id: 67a2a27090ef3c7f8957bbb3, topology_type: Unknown, servers: [<ServerDescription ('mongodb%2bsrv%3a%2f%2fxxxxx%3axxxx%40ghostxcosmoscluster.mongocluster.cosmos.azure.com%2f%3fretrywrites%3dfalse%26maxidletimems%3d120000%26tls%3dtrue%26authmechanism%3dscram-sha-256%26tlsallowinvalidcertificates%3dtrue%26appname%3dmongosh%2b1.6.0', 27017) server_type: Unknown, rtt: None, error=UnicodeError('label empty or too long')>]>