Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I handle a boto exception in python?

Tags:

python

boto

How can I wrap a boto.storage_uri() call in python so I can handle possible exceptions?

like image 849
topless Avatar asked Nov 17 '11 23:11

topless


1 Answers

Your question about Boto is a good one, not not easy to answer. The Boto exception hierarchy is poorly designed, and ultimately the only way to determine what the exception you want to trap is requires looking at the boto source code.

For example if you look at (on Ubuntu) /usr/share/pyshared/boto/exception.py you will see that there are two broad classes: boto.exception.BotoClientError boto.exception.BotoServerError

Many of the exceptions are derived from these two, though the concept of "Client" and "Server" is not very well defined and you probably would want to check for both to be sure as many exceptions can happen unexpected (as usual). However, exceptions such as boto.exception.NoAuthHandlerFound is derived directly from Exception and therefore you would have to check for it separately.

Unfortunately from looking at the code, it appears that there is neither consistency nor much care in defining the exception hierarchy in Boto, which is a flaw in Boto's design which unfortunately requires that you rely on more broad exception checking than would normally be recommended.

like image 61
GaryWiz Avatar answered Sep 27 '22 23:09

GaryWiz