topless topless - 20 days ago 6
Python Question

How can I handle a boto exception in python?

How can I wrap a

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

Answer

The first question is what exceptions is this call likely to generate? You do not want to make a blanket exception handler in any language. You should first take a look at the Boto documentation to see if it documents the exceptions you might see from a given call, but if not I would first try:

try:
  uri = boto.storage_uri()
except Exception as e:
  print(e)

Or log the exception (with the logging package exception method), but either way you want to take note of what types of exceptions you see while you're testing and whether you should handle any of them specially. You also may want to review the Python Tutorial section on Exceptions and Errors.