When trying to run the below python code we are encountering this error (UserWarning: Unknown option ssl_ca_certs warnings.warn(str(exc)) )
import pymongo import os import json client = pymongo.MongoClient("mongodb://anka202108@slaf-dev.cluster-crmfuodns4uu.us-east-2.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=D:\\Software\\new_PEM_file\\rds-combined-ca-bundle.pem&authSource=admin") db = client.CDNDEV collection = db.MYCWT_HOTEL_BOOKED json_folder_path = 'E:\myCWT\OneDrive_2023-07-05 (2)\Json100' def replace_dot_in_keys(data): if isinstance(data, list): for item in data: replace_dot_in_keys(item) elif isinstance(data, dict): for key in list(data.keys()): if '.' in key: new_key = key.replace('.', '') data[new_key] = data.pop(key) for value in data.values(): replace_dot_in_keys(value) for filename in os.listdir(json_folder_path): if filename.endswith('.json'): with open(os.path.join(json_folder_path, filename)) as json_file: data = json.load(json_file) replace_dot_in_keys(data) collection.insert_many(data) print(f"{filename} uploaded to MongoDB")
Error:E:\myCWT\venv\lib\site-packages\pymongo\common.py:840: UserWarning: Unknown option ssl_ca_certs
warnings.warn(str(exc))
Traceback (most recent call last):
File "E:\myCWT\Step 3\Mongodb.py", line 30, in <module>
collection.insert_many(data)
File "E:\myCWT\venv\lib\site-packages\pymongo\_csot.py", line 106, in csot_wrapper
return func(self, *args, **kwargs)
File "E:\myCWT\venv\lib\site-packages\pymongo\collection.py", line 725, in insert_many
blk.execute(write_concern, session=session)
File "E:\myCWT\venv\lib\site-packages\pymongo\bulk.py", line 514, in execute
return self.execute_command(generator, write_concern, session)
File "E:\myCWT\venv\lib\site-packages\pymongo\bulk.py", line 390, in execute_command
with client._tmp_session(session) as s:
File "D:\Anaconda\lib\contextlib.py", line 112, in __enter__
return next(self.gen)
File "E:\myCWT\venv\lib\site-packages\pymongo\mongo_client.py", line 1775, in _tmp_session
s = self._ensure_session(session)
File "E:\myCWT\venv\lib\site-packages\pymongo\mongo_client.py", line 1758, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "E:\myCWT\venv\lib\site-packages\pymongo\mongo_client.py", line 1703, in __start_session
self._topology._check_implicit_session_support()
File "E:\myCWT\venv\lib\site-packages\pymongo\topology.py", line 538, in _check_implicit_session_support
self._check_session_support()
File "E:\myCWT\venv\lib\site-packages\pymongo\topology.py", line 555, in _check_session_support
readable_server_selector, self.get_server_selection_timeout(), None
File "E:\myCWT\venv\lib\site-packages\pymongo\topology.py", line 239, in _select_servers_loop
f"{self._error_message(selector)}, Timeout: {timeout}s, Topology Description: {self.description!r}"
pymongo.errors.ServerSelectionTimeoutError: slaf-dev.cluster-crmfuodns4uu.us-east-2.docdb.amazonaws.com:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076), Timeout: 30s, Topology Description: <TopologyDescription id: 64acb180dc989c3ae6eb22bc, topology_type: Unknown, servers: [<ServerDescription ('slaf-dev.cluster-crmfuodns4uu.us-east-2.docdb.amazonaws.com', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('slaf-dev.cluster-crmfuodns4uu.us-east-2.docdb.amazonaws.com:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')>]>
We have taken different steps like changing the interpreter, updating the pip and pymongo and have also tried to force install the pip but nothing works. we are getting the same error. An early response would be appreciated. Thanks in advance.