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 @@ -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 "
You can’t perform that action at this time.
0 commit comments