def main(client, order_id):
  # Initialize appropriate service.
  line_item_service = client.GetService('LineItemService', version='v201505')
  # Initialize a DataDownloader.
  report_downloader = client.GetDataDownloader(version='v201505')

  # Filter for line items of a given order.
  values = [{
      'key': 'orderId',
      'value': {
          'xsi_type': 'NumberValue',
          'value': order_id
      }
  }]
  query = 'WHERE orderId = :orderId'

  # Create a filter statement.
  statement = dfp.FilterStatement(query, values)

  # Collect all line item custom field IDs for an order.
  custom_field_ids = set()

  # Get users by statement.
  while True:
    response = line_item_service.getLineItemsByStatement(
        statement.ToStatement())
    if 'results' in response:
      # Get custom field IDs from the line items of an order.
      for line_item in response['results']:
        if 'customFieldValues' in line_item:
          for custom_field_value in line_item['customFieldValues']:
            custom_field_ids.add(custom_field_value['customFieldId'])
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  # Create statement object to filter for an order.
  filter_statement = {'query': query, 'values': values}

  # Create report job.
  report_job = {
      'reportQuery': {
          'dimensions': ['LINE_ITEM_ID', 'LINE_ITEM_NAME'],
          'statement': filter_statement,
          'columns': ['AD_SERVER_IMPRESSIONS'],
          'dateRangeType': 'LAST_MONTH',
          'customFieldIds': list(custom_field_ids)
      }
  }

  try:
    # Run the report and wait for it to finish.
    report_job_id = report_downloader.WaitForReport(report_job)
  except errors.DfpReportError, e:
    print e % 'Failed to generate report. Error was: %s'

  # Change to your preferred export format.
  export_format = 'CSV_DUMP'

  report_file = tempfile.NamedTemporaryFile(suffix='.csv.gz', delete=False)

  # Download report data.
  report_downloader.DownloadReportToFile(
      report_job_id, export_format, report_file)

  report_file.close()

  # Display results.
  print 'Report job with id \'%s\' downloaded to:\n%s' % (
      report_job_id, report_file.name)
dataset/ETHPy150Open googleads/googleads-python-lib/examples/dfp/v201505/report_service/run_report_with_custom_fields.py/main/swapped operands of `%`