mckruasan
@mckruasan
Junior Python, Html, CSS

Не удается подключиться к MongoDB?

Делаю систему варнов в Discord.py, но получаю ошибку
Вот код:
import discord
from discord.ext import commands
from pymongo import MongoClient
import os

bot = commands.Bot(command_prefix='.')
cluster = MongoClient("mongodb+srv://mckruasan:<тут пароль есть>@cluster0.qr6z7.mongodb.net/warns?retryWrites=true&w=majority")
collusers = cluster.warns.collusers
collservers = cluster.warns.collservers

@bot.event
async def on_ready():
    await bot.change_presence(status=discord.Status.online, activity=discord.Game("m.help"))
    for guild in bot.guilds:
        for member in guild.members:
            values = {
                "_id": member.id,
                "guild_id": guild.id,
                "warns": 0,
                "reasons": []
            }
            server_values = {
                "_id": guild.id,
                "case": 0
            }

            if collusers.count_documents({"_id": member.id, "guild_id": guild.id}) == 0:
                collusers.insert_one(values)
            if collservers.count_documents({"_id": guild.id}) == 0:
                collservers.insert_one(server_values)

@bot.event
async def on_member_join(member):
    values = {
        "_id": member.id,
        "guild_id": guild.id,
        "warns": 0,
        "reasons": []
    }
    if collusers.count_documents({"_id": member.id, "guild_id": guild.id}) == 0:
        collusers.insert_one(values)

@bot.event
async def on_guild_join(guild):
    server_values = {
        "_id": guild.id,
        "case": 0
    }
    if collservers.count_documents({"_id": guild.id}) == 0:
        collservers.insert_one(server_values)

bot.run('токен')

Вот ошибка:
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "test.py", line 27, in on_ready
if collusers.count_documents({"_id": member.id, "guild_id": guild.id}) == 0:
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\collection.py", line 1811, in count_documents
return self._retryable_non_cursor_read(_cmd, session)
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\collection.py", line 1816, in _retryable_non_cursor_read
with client._tmp_session(session) as s:
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\mongo_client.py", line 1676, in _tmp_session
s = self._ensure_session(session)
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\mongo_client.py", line 1663, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\mongo_client.py", line 1608, in __start_session
self._topology._check_implicit_session_support()
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\topology.py", line 519, in _check_implicit_session_support
self._check_session_support()
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\topology.py", line 535, in _check_session_support
self._select_servers_loop(
File "C:\Users\kruasan\AppData\Local\Programs\Python\Python38\lib\site-packages\pymongo\topology.py", line 227, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-00.qr6z7.mongodb.net:27017: connection closed,cluster0-shard-00-02.qr6z7.mongodb.net:27017: connection closed,cluster0-shard-00-01.qr6z7.mongodb.net:27017: [WinError 10054] Удаленный хост принудительно разорвал существующее подключение, Timeout: 30s, Topology Description: , , ]>

Python 3.8.0
Discord.py
(Мои коллекции:)
6278c6d806cf1313008655.png
  • Вопрос задан
  • 248 просмотров
Решения вопроса 1
mckruasan
@mckruasan Автор вопроса
Junior Python, Html, CSS
Решил проблему добавив айпи 0.0.0.0 в вайт-лист.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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