Base Exception Class for GCP Python Library: "google-api-python-client" -
i using google-api-python-client library, provided google cloud. using lot of methods it, operate on compute-engine resources (disks, instances, snapshots etc) while doing lot of operations, better handling , resilient code, should add try..catch blocks & while adding blocks, realized google-cloud doesn't provide basic exception class.
worst case have thought of is:
try: <code> except: <prompt error> but believe isn't right way do.
am missing ? or exception handler isn't provided gcp-library?
i gone through documentation , error stack api returns & able figure out way handle errors handle exceptions in our code.
so, unlike mentioned, possible..!
using following way, handle errors/exceptions.
import oauth2client.client googleapiclient import discovery import googleapiclient.errors # # prepare credentials dictionary # try: compute = discovery.build( "compute", "v1", credentials=credentials) except oauth2client.client.httpaccesstokenrefresherror e: print 'error > ', e.message except googleapiclient.errors.httperror e: reason = str(e._get_reason).split("\"")[-2] print 'error > ', reason i hope, helpful!
these 2 common errors come up. there might other errors, dependent on case.
but errors should present in googleapiclient.errors class
@bill prin, please let me know.
Comments
Post a Comment