I need help setting up my mongodb atlas to my bot

I don’t know why it’s not accepting my mongo db atlas thing, i tried placing my password with <> and without <> and still i have the same error

Traceback (most recent call last):
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 849, in runner
    await self.start(token, reconnect=reconnect)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 777, in start
    await self.login(token)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 621, in login
    await self.setup_hook()
  File "RP-Utilities-Beta/bot.py", line 31, in setup_hook
    await self.database.connect(os.environ['database'])
  File "/home/runner/RP-Utilities/RP-Utilities-Beta/rpu_database.py", line 11, in connect
    self.dev_client = motor.motor_asyncio.AsyncIOMotorClient(connection_uri)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/motor/core.py", line 148, in __init__
    delegate = self.__delegate_class__(*args, **kwargs)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/pymongo/mongo_client.py", line 766, in __init__
    res = uri_parser.parse_uri(
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/pymongo/uri_parser.py", line 532, in parse_uri
    user, passwd = parse_userinfo(userinfo)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/pymongo/uri_parser.py", line 88, in parse_userinfo
    raise InvalidURI(
pymongo.errors.InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plus

i’m trying to parse this to my URI part:

mongodb+srv://<UserName>:<password>@rpucloudserver.bscpl0p.mongodb.net/?retryWrites=true&w=majority

and yeah, i’m parsing it as a secret so noone will see it

copy the output when you paste in Console:

import os
from urllib import parse

parse.quote_plus(os.environ['database'])

and store that as your secret

okay so i got this:

Traceback (most recent call last):
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/asyncio/base_events.py", line 1103, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/asyncio/base_events.py", line 1133, in _create_connection_transport
    await waiter
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/asyncio/sslproto.py", line 534, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/asyncio/sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/ssl.py", line 975, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 849, in runner
    await self.start(token, reconnect=reconnect)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 777, in start
    await self.login(token)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 612, in login
    data = await self.http.static_login(token)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/discord/http.py", line 803, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/discord/http.py", line 625, in request
    async with self.__session.request(method, url, **kwargs) as response:
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/aiohttp/client.py", line 536, in _request
    conn = await self._connector.connect(
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/aiohttp/connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/aiohttp/connector.py", line 1209, in _create_direct_connection
    raise last_exc
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/aiohttp/connector.py", line 1178, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/home/runner/RP-Utilities/.pythonlibs/lib/python3.10/site-packages/aiohttp/connector.py", line 982, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host discord.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1007)')]
import bot_token
import discord
from discord import app_commands
import asyncio
from discord.ext import commands
import os
from rpu_database import Database
import os
from urllib import parse

bot_status = ["initializing", "active", "shutting down"]
DEFAULT_PREFIX = "rpu->"
EXTENSIONS = [
    'jishaku',
]
INTENTS = discord.Intents.default()
INTENTS.message_content = True


class Bot(commands.Bot):

  def __init__(self) -> None:
    super().__init__(
        intents=INTENTS,
        command_prefix=prefix_setup,
        case_insensitive=True,
    )
    self.database = Database()
    print("Bot Connected!")

  async def setup_hook(self) -> None:
    await self.database.connect(parse.quote_plus(os.environ['database']))
    self.db_loop = self.database.dev_client.get_io_loop()
    for extension in EXTENSIONS:
      await self.load_extension(extension)
    await self.add_cog(PrefixCog(self))
    for filename in os.listdir("./RP-Utilities-Beta/cogs"):
      if filename.endswith(".py"):
        await self.load_extension(f"cogs.{filename[:-3]}")
    guild = discord.Object(1135999359985647706)
    await self.tree.sync()

  async def close(self) -> None:
    await super().close()
    await self.database.close()


async def prefix_setup(bot, message):
  prefix = await bot.database.get_prefix(guild_id=message.guild.id)
  if prefix:
    return prefix
  else:
    return DEFAULT_PREFIX


class PrefixCog(commands.Cog):

  def __init__(self, bot: Bot) -> None:
    self.bot = bot

  @commands.hybrid_group(name="prefix",
                         fallback="help",
                         invoke_without_command=True)
  async def _prefix(self, ctx: commands.Context, *, prefix: str) -> None:
    await ctx.send(
        "Use this command to set or reset the this bot prefix in your server")

  @_prefix.command(name="set")
  async def _prefix_set(self, ctx: commands.Context, *, prefix: str) -> None:
    await self.bot.database.set_prefix(guild_id=ctx.guild.id, prefix=prefix)
    await ctx.send(f"Prefix set to `{prefix}`.")

  @_prefix.command(name="reset")
  async def _prefix_reset(self, ctx: commands.Context) -> None:
    await self.bot.database.remove_prefix(guild_id=ctx.guild.id)
    await ctx.send(f"The prefix has been reset to `{DEFAULT_PREFIX}`.")


Bot().run(bot_token.return_token())

That’s a Replit issue, please watch this topic:

1 Like