title: ServerSelectionTimeoutError: basicdatabase-w4eg3.mongodb.net:27017: [Errno 11001] getaddrinfo failed
body: <p>I don't understand  why this error is occurring in my code while connecting the code to the database of MongoDB. Here is my code:-</p>
  
  <pre><code>import Credentials
  client = Credentials.client
  db = client.VisitorBook
  company = input('Enter Company Name: ')
  result=db.Company_name.insert_one({'Name':company})
  print(result.inserted_id)
  </code></pre>
  
  <p>And this is my Credentials file which I have made seperately and this Credentials module is called in the above code:</p>
  
  <pre><code>from pymongo import MongoClient
  from bson.objectid import ObjectId
  client = MongoClient('mongodb+srv://Username:&lt;Password&gt;@basicdatabase-w4eg3.mongodb.net/test?retryWrites=true');
  </code></pre>
  
  <p>After entering my username and password when I execute my code it shows this error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  ServerSelectionTimeoutError               Traceback (most recent call last)
  &lt;ipython-input-10-754b7e794657&gt; in &lt;module&gt;()
        5 
        6 company = input('Enter Company Name: ')
  ----&gt; 7 result=db.Company_name.insert_one({'Name':company})
        8 print(result.inserted_id)
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\collection.py in insert_one(self, document, bypass_document_validation, session)
      681             self._insert(document,
      682                          bypass_doc_val=bypass_document_validation,
  --&gt; 683                          session=session),
      684             self.write_concern.acknowledged)
      685 
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\collection.py in _insert(self, docs, ordered, check_keys, manipulate, write_concern, op_id, bypass_doc_val, session)
      597             return self._insert_one(
      598                 docs, ordered, check_keys, manipulate, write_concern, op_id,
  --&gt; 599                 bypass_doc_val, session)
      600 
      601         ids = []
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\collection.py in _insert_one(self, doc, ordered, check_keys, manipulate, write_concern, op_id, bypass_doc_val, session)
      577 
      578             result = self.__database.client._retryable_write(
  --&gt; 579                 True, _insert_command, session)
      580             _check_write_command_response(result)
      581         else:
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py in _retryable_write(self, retryable, func, session)
     1099     def _retryable_write(self, retryable, func, session):
     1100         """Internal retryable write helper."""
  -&gt; 1101         with self._tmp_session(session) as s:
     1102             return self._retry_with_session(retryable, func, s, None)
     1103 
  
  C:\ProgramData\Anaconda3\lib\contextlib.py in __enter__(self)
       79     def __enter__(self):
       80         try:
  ---&gt; 81             return next(self.gen)
       82         except StopIteration:
       83             raise RuntimeError("generator didn't yield") from None
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py in _tmp_session(self, session, close)
     1405             return
     1406 
  -&gt; 1407         s = self._ensure_session(session)
     1408         if s and close:
     1409             with s:
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py in _ensure_session(self, session)
     1392             # Don't make implied sessions causally consistent. Applications
     1393             # should always opt-in.
  -&gt; 1394             return self.start_session(causal_consistency=False)
     1395         except (ConfigurationError, InvalidOperation):
     1396             # Sessions not supported, or multiple users authenticated.
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py in start_session(self, causal_consistency)
     1370 
     1371         # Raises ConfigurationError if sessions are not supported.
  -&gt; 1372         server_session = self._get_server_session()
     1373         opts = client_session.SessionOptions(
     1374             causal_consistency=causal_consistency)
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\mongo_client.py in _get_server_session(self)
     1378     def _get_server_session(self):
     1379         """Internal: start or resume a _ServerSession."""
  -&gt; 1380         return self._topology.get_server_session()
     1381 
     1382     def _return_server_session(self, server_session, lock):
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py in get_server_session(self)
      425                             any_server_selector,
      426                             self._settings.server_selection_timeout,
  --&gt; 427                             None)
      428                 elif not self._description.readable_servers:
      429                     self._select_servers_loop(
  
  C:\ProgramData\Anaconda3\lib\site-packages\pymongo\topology.py in _select_servers_loop(self, selector, timeout, address)
      197             if timeout == 0 or now &gt; end_time:
      198                 raise ServerSelectionTimeoutError(
  --&gt; 199                     self._error_message(selector))
      200 
      201             self._ensure_opened()
  
  ServerSelectionTimeoutError: basicdatabase-w4eg3.mongodb.net:27017: [Errno 11001] getaddrinfo failed
  </code></pre>