def main(client, ad_group_id):
  # Initialize appropriate service with validate only flag enabled.
  client.validate_only = True
  ad_group_ad_service = client.GetService('AdGroupAdService', version='v201509')

  # Construct operations to add a text ad.
  operations = [{
      'operator': 'ADD',
      'operand': {
          'xsi_type': 'AdGroupAd',
          'adGroupId': ad_group_id,
          'ad': {
              'xsi_type': 'TextAd',
              'finalUrls': ['http://www.example.com'],
              'displayUrl': 'example.com',
              'description1': 'Visit the Red Planet in style.',
              'description2': 'Low-gravity fun for everyone!',
              'headline': 'Luxury Cruise to Mars'
          }
      }
  }]
  ad_group_ad_service.mutate(operations)
  # No error means the request is valid.

  # Now let's check an invalid ad using a very long line to trigger an error.
  operations = [{
      'operator': 'ADD',
      'operand': {
          'xsi_type': 'AdGroupAd',
          'adGroupId': ad_group_id,
          'ad': {
              'xsi_type': 'TextAd',
              'url': 'http://www.example.com',
              'displayUrl': 'example.com',
              'description1': 'Visit the Red Planet in style.',
              'description2': 'Low-gravity fun for all astronauts in orbit',
              'headline': 'Luxury Cruise to Mars'
          }
      }
  }]
  try:
    ad_group_ad_service.mutate(operations)
  except suds.WebFault, e:
    print 'Validation correctly failed with \'%s\'.' % str(e)
dataset/ETHPy150Open googleads/googleads-python-lib/examples/adwords/v201509/campaign_management/validate_text_ad.py/main/original