Make a custom exception

Question:

i have a bot and sometimes i get this error:

raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='127.0.0.1', 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.

Asked By: Auxence Drin

||

Answers:

Just import the error:

from requests.exceptions import ConnectionError

try:
    pass # your code here
except ConnectionError:
    pass # your error handler
Answered By: Ivan Chernyshov
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.