@Frotryi
Живу не тужу

Как подключиться к базе данных mongodb?

from pymongo import MongoClient
import pymongo
import dns

cluster = pymongo.MongoClient("mongodb+srv://Doodle:password@cluster5.r6uxz.mongodb.net/testdata?retryWrites=true&w=majority")
db=cluster["testdata"]
collection=db["vvvvv"]
name=input(">")

collection.insert_one({"_id":1, "name":name})


Я хочу подключиться к базе данных mongodb
И мне вылетает ошибка:

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pymongo/srv_resolver.py", line 72, in _resolve_uri
    results = resolver.query('_mongodb._tcp.' + self.__fqdn, 'SRV',
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/dns/resolver.py", line 1100, in query
    return get_default_resolver().query(qname, rdtype, rdclass, tcp, source,
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/dns/resolver.py", line 900, in query
    timeout = self._compute_timeout(start, lifetime)
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/dns/resolver.py", line 799, in _compute_timeout
    raise Timeout(timeout=duration)
dns.exception.Timeout: The DNS operation timed out after 20.001204252243042 seconds

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
    start(fakepyfile,mainpyfile)
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
    exec(open(mainpyfile).read(),  __main__.__dict__)
  File "<string>", line 5, in <module>
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pymongo/mongo_client.py", line 639, in __init__
    res = uri_parser.parse_uri(
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pymongo/uri_parser.py", line 500, in parse_uri
    nodes = dns_resolver.get_hosts()
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pymongo/srv_resolver.py", line 102, in get_hosts
    _, nodes = self._get_srv_response_and_hosts(True)
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pymongo/srv_resolver.py", line 83, in _get_srv_response_and_hosts
    results = self._resolve_uri(encapsulate_errors)
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/pymongo/srv_resolver.py", line 79, in _resolve_uri
    raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: The DNS operation timed out after 20.001204252243042 seconds

[Program finished]

Как исправить?
  • Вопрос задан
  • 168 просмотров
Пригласить эксперта
Ответы на вопрос 1
@ntexist
Студент, самоучка
Внимательно читаем логи и видим
dns.exception.Timeout: The DNS operation timed out after 20.001204252243042 seconds
Ответ написан
Ваш ответ на вопрос

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

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