M
M
Mikhail2021-09-18 19:18:19
Python
Mikhail, 2021-09-18 19:18:19

What to do if it gives an error when changing data in a MONGO DB collection?

I decided after a long time of using SQLite to take on MongoDB, but immediately got an error when I started adding data (but it had been a while before that). The error says that the session connection time has expired.
I've been sitting for the fifth hour already, I've climbed wherever possible I went to the stack https://stackoverflow.com/questions/67585023/ssl-c... I
looked there, downloaded some kind of certificate, installed it and still does not work
Please help I want to master MongoDB
Code (I wrote a bot for VK):

from vkbottle.bot import Bot, Message
from config import mainsettings
import asyncio
import random
from random import randint
from pymongo import MongoClient
 
bot = Bot(token=mainsettings['token'])
cluster = MongoClient(f"mongodb+srv://zaralx:{mainsettings['clusterpassword']}@profile.t2cgz.mongodb.net/VkProfile?retryWrites=true&w=majority")
db = cluster.VkProfile
UserColl = db.User
 
@bot.on.private_message()
async def message_handler(message: Message):
  if message.text == "Начать":
    UserColl.insert_one({"_id": 1, "name": "Player"+str(random.randint(10000, 99999999)), "Cash": 0})
    await message.answer("Done")
  else:
    pass
  # Главную откроет
bot.run_forever()


The error it gives:
Traceback (most recent call last):
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\vkbottle\dispatch\bot_router.py", line 20, in route
    await view.handle_event(event, ctx_api, self.state_dispenser)
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\vkbottle\dispatch\views\bot\message.py", line 64, in handle_event
    handler_response = await handler.handle(message, **context_variables)
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\vkbottle\dispatch\handlers\from_func_handler.py", line 26, in handle
    return await self.handler(event, **context)
  File "C:\Users\Miste\Desktop\vk\vk.py", line 25, in message_handler
    UserColl.insert_one({"_id": 1, "name": "Player"+str(random.randint(10000, 99999999)), "Cash": 0})
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\collection.py", line 705, in insert_one
    self._insert(document,
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\collection.py", line 620, in _insert
    return self._insert_one(
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\collection.py", line 609, in _insert_one
    self.__database.client._retryable_write(
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\mongo_client.py", line 1551, in _retryable_write
    with self._tmp_session(session) as s:
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\mongo_client.py", line 1948, in _tmp_session
    s = self._ensure_session(session)
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\mongo_client.py", line 1935, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\mongo_client.py", line 1883, in __start_session
    server_session = self._get_server_session()
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\mongo_client.py", line 1921, in _get_server_session
    return self._topology.get_server_session()
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py", line 520, in get_server_session
    session_timeout = self._check_session_support()
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py", line 504, in _check_session_support
    self._select_servers_loop(
  File "C:\Users\Miste\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pymongo\topology.py", line 218, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: profile-shard-00-01.t2cgz.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108),profile-shard-00-02.t2cgz.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108),profile-shard-00-00.t2cgz.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108), Timeout: 30s, Topology Description: <TopologyDescription id: 6145bb6edce2242b7dbcd19f, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('profile-shard-00-00.t2cgz.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('profile-shard-00-00.t2cgz.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')>, <ServerDescription ('profile-shard-00-01.t2cgz.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('profile-shard-00-01.t2cgz.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')>, <ServerDescription ('profile-shard-00-02.t2cgz.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('profile-shard-00-02.t2cgz.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')>]>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question