Catching Exceptions from the Python Client Library

If you're using the Python client library and encounter a server error, an exception will be generated, causing Python to stop in its tracks and print out the contents of the exception. While this is useful for debugging, in a production application you'll probably want your application to fail gracefully, perhaps displaying a nice error message to your users.

You can do this by wrapping your code in a try block and using an except statement:

  # Do something that accesses the network
except gdata.service.RequestError, inst:
  response = inst[0]
  status = response['status']
  reason = response['reason']
  body = response['body']
  # Handle the error here

Other exceptions may be thrown depending on the situation. For more information, see the gdata.service documentation.