0

我无法在 Python 客户端中使用下载报告功能。我正在使用带有 v201306 的 adwords-15.9.0。它总是失败:

$ ./classifications.py 
Traceback (most recent call last):
  File "./classifications.py", line 48, in <module>
    download_report(client, client_id)
  File "./classifications.py", line 32, in download_report
    file_path = report_downloader.DownloadReportWithAwql(report_query, 'CSV', file_path=path)
  File "/Users/mike/.virtualenvs/xxx/lib/python2.7/site-packages/adspygoogle/adwords/ReportDownloader.py", line 127, in DownloadReportWithAwql
    fileobj) or file_path
  File "/Users/mike/.virtualenvs/xxx/lib/python2.7/site-packages/adspygoogle/adwords/ReportDownloader.py", line 169, in __DownloadAdHocReportWithAwql
    return self.__DownloadReport(payload, return_micros, fileobj)
  File "/Users/mike/.virtualenvs/xxx/lib/python2.7/site-packages/adspygoogle/adwords/ReportDownloader.py", line 184, in __DownloadReport
    headers = self.__GenerateHeaders(return_micros)
  File "/Users/mike/.virtualenvs/xxx/lib/python2.7/site-packages/adspygoogle/adwords/ReportDownloader.py", line 282, in __GenerateHeaders
    self._headers['oauth2credentials'].apply(headers)
  File "/Users/mike/.virtualenvs/xxx/lib/python2.7/site-packages/oauth2client/client.py", line 533, in apply
    headers['Authorization'] = 'Bearer ' + self.access_token
TypeError: cannot concatenate 'str' and 'NoneType' objects

示例脚本get_report_fields.pyget_campaign_stats.py工作正常,但download_criteria_report.pydownload_criteria_report_with_awql.py失败并出现相同的错误。

有任何想法吗?

我的代码:

#!/usr/bin/env python

import csv
import os
import MySQLdb as mdb
from adspygoogle.adwords.AdWordsClient import AdWordsClient


MATCH_TYPES = {
    'b': 'Broad',
    'e': 'Exact',
    'p': 'Phrase',
}

DEVICE_TYPES = {
    'c': 'Desktop',
    'm': 'Mobile',
    't': 'Tablet',
}

REPORT_TYPE = 'CREATIVE_CONVERSION_REPORT'


def download_report(client, client_id):
    # Initialize appropriate service.
    report_downloader = client.GetReportDownloader(version='v201306')

    # Create report query.
    report_query = ('SELECT AdGroupId', 'CampaignId', 'CreativeId FROM CREATIVE_CONVERSION_REPORT  DURING LAST_7_DAYS')

    path = '/tmp/report_%d.csv' % client_id
    file_path = report_downloader.DownloadReportWithAwql(report_query, 'CSV', file_path=path)

    print 'Report was downloaded to \'%s\'.' % file_path

if __name__ == '__main__':
    client = AdWordsClient()

    conn = mdb.connect('xxx.us-east-1.rds.amazonaws.com', 'xxx', 'xxx', 'xxx');
    with conn:
        cur = conn.cursor(mdb.cursors.DictCursor)
        cur.execute("SELECT * FROM xxx.adwords_accounts")

        rows = cur.fetchall()
        for row in rows:
            client_id = row['id']
            client.SetClientCustomerId(client_id)
            download_report(client, client_id)
4

2 回答 2

0

OAuth2Credentials如对象的属性所示,您的身份验证有access_token问题None

如果您还没有,请查看use_oath2.py示例,了解如何处理通过 OAuth2 进行的身份验证。您还需要创建一个Google API 控制台应用程序来获取客户端 ID 和密码。

于 2013-07-30T21:55:30.400 回答
0

这是一个已知的错误。已在 v15.9.1 中修复

于 2013-07-31T12:56:31.960 回答