Getting FaultMessage: Too Many

31 views
Skip to first unread message

Pratham Chauhan

unread,
Jul 26, 2024, 4:52:04 AM7/26/24
to Google Ads API and AdWords API Forum
Hey there I am getting FaultMessage: Too Many when adding more than 4 ads in the ad group using google sdk python  and FaultMessage: Too few when adding less than 3 ads in the ad group using google sdk python.
code :
import argparse
import sys
import uuid
import pandas as pd
from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException

def main(client, customer_id, df):
"""Creates ad group ads from a dataframe.

Args:
client: an initialized GoogleAdsClient instance.
customer_id: a client customer ID.
df: a dataframe containing ad group names, headlines, and descriptions.
"""
ad_group_ad_service = client.get_service("AdGroupAdService")

# Group the rows by ad group
grouped = df.groupby('Ad Group')

for ad_group_name, group in grouped:
print(f"Creating ads for ad group: {ad_group_name}")
ad_group_ad_operation = client.get_type("AdGroupAdOperation")
ad_group_ad = ad_group_ad_operation.create
ad_group_ad.status = client.enums.AdGroupAdStatusEnum.ENABLED
ad_group_ad.ad_group = ad_group_name

# Set responsive search ad info
ad_group_ad.ad.final_urls.append("https://www.example.com/")

# Collect headlines and descriptions
headlines = []
descriptions = []
for _, row in group.iterrows():
headline = row['Headline']
description = row['Description']
headlines.append(create_ad_text_asset(client, headline))
descriptions.append(create_ad_text_asset(client, description))
# Ensure there are at least 3 headlines and 2 descriptions
while len(headlines) < 3:
headlines.append(create_ad_text_asset(client, "Default Headline"))
while len(descriptions) < 2:
descriptions.append(create_ad_text_asset(client, "Default Description"))

# Add headlines and descriptions to the ad
ad_group_ad.ad.responsive_search_ad.headlines.extend(headlines)
ad_group_ad.ad.responsive_search_ad.descriptions.extend(descriptions)

# Send a request to the server to add a responsive search ad
ad_group_ad_response = ad_group_ad_service.mutate_ad_group_ads(
customer_id=customer_id, operations=[ad_group_ad_operation]
)

for result in ad_group_ad_response.results:
print(
f"Created responsive search ad with resource name "
f'"{result.resource_name}".'
)


def create_ad_text_asset(client, text, pinned_field=None):
"""Create an AdTextAsset.

Args:
client: an initialized GoogleAdsClient instance.
text: text for headlines and descriptions.
pinned_field: to pin a text asset so it always shows in the ad.

Returns:
An AdTextAsset.
"""
ad_text_asset = client.get_type("AdTextAsset")
ad_text_asset.text = text
if pinned_field:
ad_text_asset.pinned_field = pinned_field
return ad_text_asset

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description=("Creates Responsive Search Ads for specified customer.")
)
# The following argument(s) should be provided to run the example.
parser.add_argument(
"-c",
"--customer_id",
type=str,
required=True,
help="The Google Ads customer ID.",
)
args = parser.parse_args()

# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
googleads_client = GoogleAdsClient.load_from_storage(version="v17", path="./google-ads.yaml")

try:
# Load the dataframe from the provided CSV file
df = pd.read_csv("ads_df.csv")

main(
googleads_client,
args.customer_id,
df,
)
except GoogleAdsException as ex:
print(
f'Request with ID "{ex.request_id}" failed with status '
f'"{ex.error.code().name}" and includes the following errors:'
)
for error in ex.failure.errors:
print(f'Error with message "{error.message}".')
if error.location:
for field_path_element in error.location.field_path_elements:
print(f"\t\tOn field: {field_path_element.field_name}")
sys.exit(1)


Google Ads API Forum Advisor

unread,
Jul 26, 2024, 11:17:18 AM7/26/24
to chauhanp...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for contacting the Google Ads API team.

Kindly note that the provided code snippet will not be sufficient to address your issue. So to assist you further on fault message issues, kindly provide the complete API logs (request and response with request-id and request header) generated at your end where you are observing the said fault messages so that we can assist you accordingly.

Kindly note that you have to enable logging if you are using a client library. You can refer to the Python guides to enable logging on your end. For REST interface requests, you can enable logging via the curl command by using the -i flag. 

You can send the details via the Reply privately to the author option or a direct private reply to this email.

This message is in relation to case "ref:!00D1U01174p.!5004Q02vEADT:ref" (ADR-00259700)

Thanks,

 
Google Logo Google Ads API Team

Register for the upcoming workshop: Performance Max and the Google Ads API!
 


Reply all
Reply to author
Forward
0 new messages