Question

this is my code when I am trying to run it I am getting this error in the console.

path = 'MYpaath'
    report_downloader = client.GetReportDownloader(version='v201309')

    # Create report definition.
    report = {
              'reportName': 'Last 7 days CRITERIA_PERFORMANCE_REPORT',
              'dateRangeType': 'LAST_7_DAYS',
              'reportType': 'CRITERIA_PERFORMANCE_REPORT',
              'downloadFormat': 'CSV',
              'selector': {
                           'fields': ['CampaignId', 'AdGroupId', 'Id', 'CriteriaType',
                 'Criteria', 'Impressions', 'Clicks', 'Cost']
                           },
  # Enable to get rows with zero impressions.
  'includeZeroImpressions': 'false'
    }
    print("============================================",report)
    file1= report_downloader.DownloadReport(report, file_path=path)
    print 'Report was downloaded to \'%s\'.' % file1

Error I am Getting after running this

file= report_downloader.DownloadReport(report, file_path=path)
File "C:\Python27\lib\site-packages\adspygoogle-1.1.4-py2.7.egg\adspygoogle\adwords\ReportDownloader.py", line 100, in DownloadReport
fileobj = open(file_path, 'w')
IOError: [Errno 22] invalid mode ('w') or 
filename:'MYpath'
Was it helpful?

Solution

I had a similar error and it was associated with the path and the way you open the file and write to it. Set your path to the following:

path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"temp","report.csv")

This basically sets the path to: /path/to/your/python/script/TEMP/report.csv

If your temp folder or report.csv file do not exist, they will be created during the process.

After that you need to open the file, write to it, and close it. The following script can do that:

f = open(path,'wb')
f.write(report_downloader.DownloadReport(report))
f.close()

So you are basically running a download command directly into the open file and then closing it.

Hope this helps!

Aivoric

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top