Skip to content

cannot log google ads logging v19 python client #557

@locdoan12121997

Description

@locdoan12121997

Hi Google Ads team,

Since upgrading Google Ads API version to v19, I cannot get the Google Ads logging.

import asyncio
import logging
from google.protobuf.json_format import MessageToDict

logging.basicConfig(level=logging.INFO, format='[%(asctime)s - %(levelname)s] %(message).5000s')
logging.getLogger('google.ads.googleads.client').setLevel(logging.INFO)

import google.ads.googleads.client


def setup_google_ads_connection():
    google_ads_client = (
        google.ads.googleads.client.GoogleAdsClient.load_from_storage("googleads.yaml")
    )
    ga_service = google_ads_client.get_service("GoogleAdsService", version="v19")
    return google_ads_client, ga_service


async def main(google_ads_client, google_ads_service):
    cust_list = ["2978713003"]
    for cust_id in cust_list:
        asset_query = "SELECT segments.date,[campaign.id](http://campaign.id/),[ad_group.id](http://ad_group.id/),metrics.impressions,metrics.clicks,metrics.cost_micros,asset_field_type_view.field_type,metrics.video_views,metrics.cross_device_conversions FROM asset_field_type_view  WHERE segments.date >= '2025-03-05' AND segments.date <= '2025-03-05' AND metrics.impressions > 0 AND [campaign.id](http://campaign.id/) in ('21080449403')"
        setting = google_ads_client.get_type('SummaryRowSettingEnum').SummaryRowSetting.SUMMARY_ROW_WITH_RESULTS
        search_request = google_ads_client.get_type("SearchGoogleAdsStreamRequest")
        search_request.customer_id = cust_id
        search_request.query = asset_query
        search_request.summary_row_setting = setting
        _CLIENT_TIMEOUT_SECONDS = 400
        
        stream = google_ads_service.search_stream(
            search_request, 
            timeout=_CLIENT_TIMEOUT_SECONDS
        )
        result = []
        summary_result = []
        for batch in stream:
            summary_row = batch.summary_row
            summary_row = MessageToDict(
                    summary_row,
                    use_integers_for_enums=False,
                    preserving_proto_field_name=True
                )
            summary_result.append(summary_row)
            for row in batch.results:
                row = MessageToDict(
                    row,
                    use_integers_for_enums=False,
                    preserving_proto_field_name=True
                )
                result.append(row)

                
        if result:
            print(f"{cust_id} has data")

if __name__ == "__main__":
    google_ads_client, google_ads_service = setup_google_ads_connection()

    asyncio.run(
        main(google_ads_client, google_ads_service)
    )

I use python 3.12.9
Here's the version of library used in python when pip freeze

aiohttp==3.9.5
aiosignal==1.3.2
attrs==25.3.0
boto3==1.34.126
botocore==1.34.126
cachetools==5.5.2
certifi==2025.1.31
charset-normalizer==3.4.1
frozenlist==1.6.0
google-ads==26.1.0
google-api-core==2.24.2
google-auth==2.39.0
google-auth-oauthlib==1.2.2
googleapis-common-protos==1.70.0
googlemaps==4.10.0
grpcio==1.71.0
grpcio-status==1.62.3
idna==3.10
iso3166==2.1.1
jmespath==1.0.1
multidict==6.4.3
numpy==2.2.5
oauthlib==3.2.2
pandas==2.2.2
propcache==0.3.1
proto-plus==1.26.1
protobuf==4.25.7
psycopg2-binary==2.9.10
pyasn1==0.6.1
pyasn1_modules==0.4.2
python-dateutil==2.9.0.post0
pytz==2025.2
PyYAML==6.0.2
redis==5.1.1
requests==2.32.3
requests-oauthlib==2.0.0
rsa==4.9.1
s3transfer==0.10.4
six==1.17.0
tzdata==2025.2
ujson==5.10.0
urllib3==2.4.0
uvloop==0.19.0
yarl==1.20.0

P/S: when I use v17, the logging is normal.

Can you guide me through the steps to get Google Ads logging again?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions