Make a custom exception


i have a bot and sometimes i get this error:

raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='', port=23264): Max retries exceeded with url: /lol-summoner/v1/current-summoner (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000170037E5B10>: Failed to establish a new connection: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée'))

This happens but i don’t care, i just want my function to continue. I thought first that ConnectionError would the exception but she don’t work. What i need to do here to make a custom exception that work ? This seems really hard in that case, I’m still learning about requests and i never face this case.

>Solution :

Just import the error:

from requests.exceptions import ConnectionError

    pass # your code here
except ConnectionError:
    pass # your error handler

Leave a ReplyCancel reply