Hi, i'm trying to pull the data using the DownloadReportAsStream method and there are issues downloading data where i'm seeing a malformed string (not all columns posted).
I'm kind of surprised as to why all data is not downloaded.
Could you please let me know if there are any known issues with this approach?
Here is my code snippet:
"id" used below is the accountId.
report_definition = {
'dateRangeType': 'CUSTOM_DATE',
'downloadFormat': 'CSV',
'includeZeroImpressions': 'false',
'reportName': 'Daily Adwords Digest',
'reportType': 'AD_PERFORMANCE_REPORT',
'selector': {
'dateRange': {
'min': start_dt, # format is '20141117'
'max': end_dt
},
'fields': REPORT_COLUMNS,
}
}
CHUNK_SIZE = 32 * 1024
report_data = StringIO.StringIO()
stream_data = report_downloader.DownloadReportAsStream(
report_definition, skip_report_header=True, skip_column_header=True,
skip_report_summary=True, include_zero_impressions=False)
try:
while True:
chunk = stream_data.read(CHUNK_SIZE)
if not chunk: break
report_data.write(chunk.decode() if sys.version_info[0] == 3
and getattr(report_data, 'mode', 'w') == 'w' else chunk)
#report_data.seek(0)
#time.sleep(5)
data = report_data.getvalue()
#for line in report_data.split("\n"):
for line in data.split("\n"):
f.write("{},{}\n".format(id, line))
cnt += 1
except Exception as e:
logging.error("Failed to download data for AccountID %s" % id)
raise e
finally:
report_data.close()
stream_data.close()