Skip to content

Commit 7e86407

Browse files
committed
Merge remote-tracking branch 'origin/ssl-err'
2 parents 8db612b + e48eed5 commit 7e86407

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: core/clients.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,24 @@ async def setup_indexes(self):
405405
)
406406
logger.debug("Successfully configured and verified database indexes.")
407407

408-
async def validate_database_connection(self):
408+
async def validate_database_connection(self, *, ssl_retry=True):
409409
try:
410410
await self.db.command("buildinfo")
411411
except Exception as exc:
412412
logger.critical("Something went wrong while connecting to the database.")
413413
message = f"{type(exc).__name__}: {str(exc)}"
414414
logger.critical(message)
415-
415+
if "CERTIFICATE_VERIFY_FAILED" in message and ssl_retry:
416+
mongo_uri = self.bot.config["connection_uri"]
417+
if mongo_uri is None:
418+
mongo_uri = self.bot.config["mongo_uri"]
419+
for _ in range(3):
420+
logger.warning("FAILED TO VERIFY SSL CERTIFICATE, ATTEMPTING TO START WITHOUT SSL (UNSAFE).")
421+
logger.warning("To fix this warning, check there's no proxies blocking SSL cert verification, "
422+
"run \"Certificate.command\" on MacOS, "
423+
"and check certifi is up to date \"pip3 install --upgrade certifi\".")
424+
self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True).modmail_bot
425+
return await self.validate_database_connection(ssl_retry=False)
416426
if "ServerSelectionTimeoutError" in message:
417427
logger.critical(
418428
"This may have been caused by not whitelisting "

0 commit comments

Comments
 (0)