File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -407,14 +407,24 @@ async def setup_indexes(self):
407407 )
408408 logger .debug ("Successfully configured and verified database indexes." )
409409
410- async def validate_database_connection (self ):
410+ async def validate_database_connection (self , * , ssl_retry = True ):
411411 try :
412412 await self .db .command ("buildinfo" )
413413 except Exception as exc :
414414 logger .critical ("Something went wrong while connecting to the database." )
415415 message = f"{ type (exc ).__name__ } : { str (exc )} "
416416 logger .critical (message )
417-
417+ if "CERTIFICATE_VERIFY_FAILED" in message and ssl_retry :
418+ mongo_uri = self .bot .config ["connection_uri" ]
419+ if mongo_uri is None :
420+ mongo_uri = self .bot .config ["mongo_uri" ]
421+ for _ in range (3 ):
422+ logger .warning ("FAILED TO VERIFY SSL CERTIFICATE, ATTEMPTING TO START WITHOUT SSL (UNSAFE)." )
423+ logger .warning ("To fix this warning, check there's no proxies blocking SSL cert verification, "
424+ "run \" Certificate.command\" on MacOS, "
425+ "and check certifi is up to date \" pip3 install --upgrade certifi\" ." )
426+ self .db = AsyncIOMotorClient (mongo_uri , tlsAllowInvalidCertificates = True ).modmail_bot
427+ return await self .validate_database_connection (ssl_retry = False )
418428 if "ServerSelectionTimeoutError" in message :
419429 logger .critical (
420430 "This may have been caused by not whitelisting "
You can’t perform that action at this time.
0 commit comments