return nice error if oauth2service.json missing

This commit is contained in:
Jay Lee
2014-11-19 12:16:04 -05:00
parent 723e8c042a
commit bc48432a8d

24
gam.py
View File

@@ -572,18 +572,18 @@ def buildGAPIServiceObject(api, act_as=None, soft_errors=False):
oauth2servicefilep12 = u'%s.p12' % oauth2servicefile oauth2servicefilep12 = u'%s.p12' % oauth2servicefile
try: try:
json_string = open(oauth2servicefilejson).read() json_string = open(oauth2servicefilejson).read()
json_data = json.loads(json_string) except IOError, e:
try: print u'Error: %s' % e
SERVICE_ACCOUNT_EMAIL = json_data[u'web'][u'client_email'] print u''
SERVICE_ACCOUNT_CLIENT_ID = json_data[u'web'][u'client_id'] print u'Please follow the instructions at:\n\nhttps://github.com/jay0lee/GAM/wiki/CreatingClientSecretsFile#creating-your-own-oauth2servicejson\n\nto setup a Service Account'
f = file(oauth2servicefilep12, 'rb') sys.exit(6)
key = f.read() json_data = json.loads(json_string)
f.close() try:
except IOError, e: SERVICE_ACCOUNT_EMAIL = json_data[u'web'][u'client_email']
print u'Error: %s' % e SERVICE_ACCOUNT_CLIENT_ID = json_data[u'web'][u'client_id']
print u'' f = file(oauth2servicefilep12, 'rb')
print u'Please follow the instructions at:\n\nhttps://github.com/jay0lee/GAM/wiki/CreatingClientSecretsFile#creating-your-own-oauth2servicejson\n\nto setup a Service Account' key = f.read()
sys.exit(6) f.close()
except KeyError: except KeyError:
# new format with config and data in the .json file... # new format with config and data in the .json file...
SERVICE_ACCOUNT_EMAIL = json_data[u'client_email'] SERVICE_ACCOUNT_EMAIL = json_data[u'client_email']