Connecting to Cosmos DB for MongoDB account error

carom-9728 21 Reputation points
2022-11-01T19:42:27.67+00:00

I am trying to follow this tutorial: https://learn.microsoft.com/en-gb/azure/cosmos-db/mongodb/quickstart-python

However when I run the line (from the tutorial, https://github.com/Azure-Samples/azure-cosmos-db-mongodb-python-getting-started/blob/main/run.py, line 60)

   client = pymongo.MongoClient(CONNECTION_STRING)  

I get the following error

   File ...\lib\site-packages\pymongo\mongo_client.py:753, in MongoClient.__init__(self, host, port, document_class, tz_aware, connect, type_registry, **kwargs)  
       751         fqdn = res["fqdn"]  
       752     else:  
   \--> 753         seeds.update(uri_parser.split_hosts(entity, port))  
       754 if not seeds:  
       755     raise ConfigurationError("need to specify at least one host")  
     
   File ...\lib\site-packages\pymongo\uri_parser.py:371, in split_hosts(hosts, default_port)  
       369 for entity in hosts.split(","):  
       370     if not entity:  
   \--> 371         raise ConfigurationError("Empty host (or extra comma in host list).")  
       372     port = default_port  
       373     # Unix socket entities don't have ports  
     
   ConfigurationError: Empty host (or extra comma in host list).  

I am using the connection string from my Cosmos DB for MongoDB account > Connection String > Primary connection string. Any idea on how I can get past this?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,902 questions
{count} votes

Accepted answer
  1. GeethaThatipatri-MSFT 29,542 Reputation points Microsoft Employee Moderator
    2022-11-07T14:04:15.013+00:00

    @carom-9728 I tried to connect with the connection string and was able to connect successfully
    can you try with the simple code mentioned below and see if you are able to connect?

    257810-image.png

    Let us know if this helps to connect

    Regards
    Geetha


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.