googleads-python-lib
googleads-python-lib copied to clipboard
Syntax Error with run_saved_query.py
I get the following syntax error on line 39 of run_saved_query.py:
except errors.DfpReportError, e:
^
SyntaxError: invalid syntax
Here's the snipet from code (starting on line 36) that I can't figure out how to format:
try:
# Run the report and wait for it to finish.
report_job_id = report_downloader.WaitForReport(report_job)
except errors.DfpReportError, e:
print 'Failed to generate report. Error was: %s' % e
# Change to your preferred export format.
export_format = 'CSV_DUMP'
Is this a python version issue?
Thanks for the help!
Hi,
Thanks for writing in! This looks like it need to be updated. The syntax should be except errors.DfpReportError as e:
Yeah, I tried that, too, but then got an indent error.
File "dfp_api_savedquery.py", line 40
except errors.DfpReportError as e:
^
IndentationError: unexpected unindent
The indent seems right to me (with my 1-2 yrs python experience) so still trying to figure it out.
Thanks, @grivescorbett !
Weird, feel free to post to the DFP API Forum and we can give you a hand with the implementation over there.
I got the code to work by doing the following:
- At line 57, change
except errors.DfpReportError, e:
toexcept errors.DfpReportError
as
e:
- Make sure at line 57 -
except errors.DfpReportError as e:
stays underTry
on line 54. Atom editor auto-adjusted the indention incorrectly so I had to move it back. - All
Print 'string'
needs to be changed toPrint('string')
- At line 39, change
.WithBindVariable('id', long(saved_query_id))
to.WithBindVariable('id', int(saved_query_id))
Whala- everything ran after that. I know it has to do with the Python version (2 vs 3) but I am not familiar with how to work around the version changes. I'm sure there's some lib for that. I guess I'll figure that out eventually. Hope this helps!