Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error when authenticating to Google Ads API with Cloud Run app service account in docker image

Hello, 

 
I am trying to connect to my Google Ads Seat through Google Ads API. 
I have the simple following code to authenticate. 
 
###
from google.ads.googleads.client import GoogleAdsClient
DEVELOPER_TOKEN = "xxxx"  => Developer token in string
USE_PROTO_PLUS = "true"
JSON_KEY_FILE_PATH = '/app/service-account.json'  ==> the absolute path in string of the service account json file within the docker image which has been authorized for adwords scope
IMPERSONATED_EMAIL = "em...@gmail.com"  ==> the email of the admin on this service account in string
LOGIN_CUSTOMER_ID = "0123456789"  ==> The ID in string of my Google Ads Seat 
 
credentials = {
                    "developer_token":  DEVELOPER_TOKEN ,
                    "use_proto_plus":  USE_PROTO_PLUS ,
                    "json_key_file_path":  JSON_KEY_FILE_PATH ,
                    "impersonated_email":  IMPERSONATED_EMAIL ,
                    "login_customer_id":  LOGIN_CUSTOMER_ID
                }
client = GoogleAdsClient.load_from_dict(credentials)
###
 
When I run it locally it works perfectly (in locally deployed docker image). However, when my application is deployed on Cloud Run and run in docker image on Google Cloud Platform I have the following error : "[Errno 21] Is a directory: '/app/service-account.json' ". 
I am kind of lost because this code works perfectly locally. I don't understand why it's reading this JSON_KEY_FILE_PATH variable as a directory and not as a path since it has the .json extension. 
The file is well existing in the docker image. 
Do you know where this could come from ? 
 
I have already ask for help on the Google Ads forum but they said it would rather be a GCP issue. 
 
Thanks in advance, 
 
Adelaide
0 1 1,153
1 REPLY 1

Hi,

This could be an issue with managing the Service Account. Did you activate your service account properly? 

If not, please review the document below [1] & [2] and let us know.

Also, make sure you put the JSON file in the right folder so the service account will be able to authenticate.

 

[1] https://cloud.google.com/iam/docs/creating-managing-service-account-keys

[2] https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-account