@Vlad1779

Tracebak ошибка в pymongo?

Сделал тестовую бд на MongoDB используя Python. Но Tracebak выдает ошибку.

Вот мой код:
from pymongo import MongoClient
import os
from random import randint

cluster = MongoClient(os.getenv("MONGO_URL"))
db = cluster["testdata"]
collection = db["testdata"]


name = input("> ")


post = {
    "id": 1,
    "name": name,
    "balance": randint(1, 100),
  }


collection.insert_one(post)


А вот ошибка:
Traceback (most recent call last):
  File "main.py", line 14, in <module>
    collection.insert_one(
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/collection.py", line 628, in insert_one
    self._insert_one(
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/collection.py", line 569, in _insert_one
    self.__database.client._retryable_write(acknowledged, _insert_command, session)
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1475, in _retryable_write
    with self._tmp_session(session) as s:
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1757, in _tmp_session
    s = self._ensure_session(session)
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1740, in _ensure_session
    return self.__start_session(True, causal_consistency=False)
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1685, in __start_session
    self._topology._check_implicit_session_support()
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/topology.py", line 538, in _check_implicit_session_support
    self._check_session_support()
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/topology.py", line 554, in _check_session_support
    self._select_servers_loop(
  File "/home/runner/mongo/venv/lib/python3.10/site-packages/pymongo/topology.py", line 238, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: ac-ummmoju-shard-00-01.vfnkaco.mongodb.net:27017: connection closed,ac-ummmoju-shard-00-00.vfnkaco.mongodb.net:27017: connection closed,ac-ummmoju-shard-00-02.vfnkaco.mongodb.net:27017: connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 647a31d65f138a238c8b4f15, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('ac-ummmoju-shard-00-00.vfnkaco.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ummmoju-shard-00-00.vfnkaco.mongodb.net:27017: connection closed')>, <ServerDescription ('ac-ummmoju-shard-00-01.vfnkaco.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ummmoju-shard-00-01.vfnkaco.mongodb.net:27017: connection closed')>, <ServerDescription ('ac-ummmoju-shard-00-02.vfnkaco.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('ac-ummmoju-shard-00-02.vfnkaco.mongodb.net:27017: connection closed')>]>
  • Вопрос задан
  • 60 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы