Correct exception handling with openrouteservice.exceptions

Good morning,
I’m trying to create a try/except block to catch timeout and api errors, but It doesnt seem to recognize the errors, for example:


  api_key = 'erersfsdfdsfdsfs'

except openrouteservice.exceptions.ApiError:
   slck.send('API out of tokens, refresh)

Which would send an slack message on failure, same logic with timeout. Can someone point my error?

What should throw an error there? It’s just an assignment…

If you would actually do a request with that API key to our servers, you’d get a 403 - Unauthorized and trigger a ApiError.

Yes, this is part of a larger script and I throws the expected 403, the problem is that it doesnt send the message. I tried a simpler "print something) and didnt either, so the problem is in how the error is catched isnt it?

In general id would be helpful if you actually include the part that would throw the error.
As nils mentioned, the assignment will never throw an error.

You could check for general Exception and inspect if it really is


you are looking for.

But again, without context it’s hard to say what your problem is.