PolicyViolationError Troubleshooting during batch uploads

115 views
Skip to first unread message

Nellle Rickchards

unread,
Aug 28, 2018, 1:29:15 PM8/28/18
to AdWords API and Google Ads API Forum
Hello,
I'm batch uploading 1000s of adds. I'm running into this failure:


Operation 221 - FAILURE:
errorType=PolicyViolationError
trigger=None
errorString=AdPolicyError.POLICY_ERROR
fieldPath=operations[221].operand.ad.headlinePart1
Traceback (most recent call last):
  File "create-text-ads.py", line 75, in <module>
    campaign_batch_upload.PrintResponse(batch_job_helper, response)
  File "/Users/***/Projects/adwords-management/campaign_batch_upload.py", line 302, in PrintResponse
    print ('\treason=%s' % data['errorList']['errors']['reason'])
KeyError: 'reason'


Is there a way to get more details about the PolicyViolation (ex: what headline text is causing it)? 

Milind Sankeshware (AdWords API Team)

unread,
Aug 28, 2018, 5:50:21 PM8/28/18
to AdWords API and Google Ads API Forum
Hi Nellle,

In AdWords API, you will be able to submit policy exemption requests for those policy violations which has isExemptable as true. Please refer to this section of guide for more details and code samples. If you are still facing issues, could you please enable logging and share the SOAP request and response logs generated when you encountered the AdPolicyError.POLICY_ERROR error? Also, you can refer to this guide to check ad policies. You can choose 'Reply privately to author' option while responding.

Thanks,
Milind, AdWords API Team

Nellle Rickchards

unread,
Aug 30, 2018, 1:00:29 PM8/30/18
to AdWords API and Google Ads API Forum
Thanks!

I figured out the problem. Our ad is for motorcycle exhausts and pipes. "pipes" is triggered as advertising tobacco. The issue is I can't figure out how to set isExempted = True in a batch upload. The documentation using the AdGroupService.

Here is my code:
if create_ads:
    # Initialize BatchJobHelper.
    client = adwords.AdWordsClient.LoadFromStorage(yaml_path)
    batch_job_helper = client.GetBatchJobHelper(version='v201802')

    # Create a BatchJob.
    batch_job = campaign_batch_upload.AddBatchJob(client)

    # Retrieve the URL used to upload the BatchJob operations.
    upload_url = batch_job['uploadUrl']['url']
    batch_job_id = batch_job['id']
    print ('Created BatchJob with ID "%d", status "%s", and upload URL "%s"' % (
        batch_job['id'], batch_job['status'], upload_url))

    # Generate operations to upload.
    ad_operations = campaign_batch_upload.BuildAdGroupAdOperations(
        batch_job_helper, create_ads)

    # Upload operations.
    batch_job_helper.UploadOperations(
        upload_url, ad_operations)

   # Download and display results.
    download_url = campaign_batch_upload.GetBatchJobDownloadUrlWhenReady(client, batch_job_id)
    response = requests.get(download_url).content
    campaign_batch_upload.PrintResponse(batch_job_helper, response)
    helpers.update_ad_id(response)

else:
    print('Not ads to create')


Milind Sankeshware (AdWords API Team)

unread,
Aug 30, 2018, 5:26:13 PM8/30/18
to AdWords API and Google Ads API Forum
Hi Nellle,

You will need to identify the Ads that failed creation in the BatchJob's response. Once you know the specific Ads, you can have a logic to validate the isExemptable flag as in this code example and upload the ones with isExemptable = true along with the exemption request. However, please note that you may need to perform this synchronously using the AdGroupAdService or create a new BatchJob for this operation exclusively. Let me know if you have any further questions.

Nellle Rickchards

unread,
Sep 5, 2018, 5:56:55 PM9/5/18
to AdWords API and Google Ads API Forum
Sounds good! Do you know if I can update the script to continue to the next Operation after a policy error? Currently the policy errors are causing the batch upload to completely stop.

Milind Sankeshware (AdWords API Team)

unread,
Sep 6, 2018, 3:43:42 PM9/6/18
to AdWords API and Google Ads API Forum
Hi Neil,

In the batch job, the operations that are not dependent on each other should not be impacted by the failure(policy error) of one operation. In your batch job set the partialFailure tag to TRUE. This means that when an operation fails it returns the error at the end without disrupting the other operations. For more information please refer to this guide. Let me know if you have any further questions. 

Nellle Rickchards

unread,
Sep 18, 2018, 1:06:51 PM9/18/18
to AdWords API and Google Ads API Forum
For some reason the responses in PrintResponse() would causes errors making the entire batch upload stop. I commented out the print statements and it runs fine, however it's not ideal as I  no longer get helpful error messages.

Milind Sankeshware (AdWords API Team)

unread,
Sep 18, 2018, 5:30:47 PM9/18/18
to AdWords API and Google Ads API Forum
Hi Neil,

Could you please share the logs for the batch job along with the batch job id for failed and passed requests so that I can troubleshoot the issue? You can chose the 'Reply privately to author' option while responding. 
Reply all
Reply to author
Forward
0 new messages