UnicodeDecodeError on DownloadReportAsStringWithAwql

163 views
Skip to first unread message

João Aparício

unread,
Apr 28, 2015, 5:49:59 AM4/28/15
to adwor...@googlegroups.com
Not much more to say apart from the title.

I have the code:

    report_downloader = client.GetReportDownloader(version='v201409')
    report_query = ('SELECT Impressions,QualityScore,KeywordText ' +
                    'FROM KEYWORDS_PERFORMANCE_REPORT ' +
                    'WHERE Impressions > 0 ' +
                    'DURING YESTERDAY ')
    r = report_downloader.DownloadReportAsStringWithAwql(report_query, 'CSV').splitlines()

And I get the exception:

    Traceback (most recent call last):
      File "qs_tracking.py", line 100, in <module>
        qs_report(list_of_customer_ids, tracking_config)
      File "qs_tracking.py", line 68, in qs_report
        r = qs_report_one_acc(client)
      File "qs_tracking.py", line 34, in qs_report_one_acc
        r = report_downloader.DownloadReportAsStringWithAwql(report_query, 'CSV').splitlines()
      File "/usr/local/lib/python2.7/dist-packages/googleads/adwords.py", line 635, in DownloadReportAsStringWithAwql
        return response.read().decode()
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 55408: ordinal not in range(128)

This only happens in one of my accounts. In the others this code runs fine.


Anash P. Oommen (AdWords API Team)

unread,
Apr 28, 2015, 2:34:13 PM4/28/15
to adwor...@googlegroups.com
Hi Joao,

Could you please fine a bug with the Python client library at https://github.com/googleads/googleads-python-lib/issues? The report is encoded in UTF-8, so I suspect that the library is picking an incorrect encoder.

A temporary workaround would be to download the report as GZIPPED_CSV instead of CSV, and then unzip it in memory.

Cheers,
Anash P. Oommen,
AdWords Scripts Team.

João Aparício

unread,
May 6, 2015, 12:10:08 PM5/6/15
to adwor...@googlegroups.com
That doesn't seem to work, unfortunately.

Code:

      r = report_downloader.DownloadReportAsStringWithAwql(report_query, 'GZIPPED_CSV')

Error:

    Traceback (most recent call last):
      File "get_keywords_ids.py", line 84, in <module>
        get_kws_one_acc(acc_id)
      File "get_keywords_ids.py", line 51, in get_kws_one_acc
        r = report_downloader.DownloadReportAsStringWithAwql(report_query, 'GZIPPED_CSV')
      File "/usr/local/lib/python2.7/dist-packages/googleads/adwords.py", line 635, in DownloadReportAsStringWithAwql
        return response.read().decode()
    UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128)

Anash P. Oommen (AdWords API Team)

unread,
May 7, 2015, 9:11:58 AM5/7/15
to adwor...@googlegroups.com, jpmn.a...@gmail.com
Hi,

Looks like this is now being tracked on https://github.com/googleads/googleads-python-lib/issues/55. Could you subscribe to that thread? The library owner is already on that thread, and he will work with you to get the issue fixed.

Cheers,
Anash
Reply all
Reply to author
Forward
0 new messages