googleads / googleads-python-lib

The Python client library for Google's Ads APIs
Apache License 2.0
685 stars 975 forks source link

Syntax Error with run_saved_query.py #295

Open atlas-g0d opened 6 years ago

atlas-g0d commented 6 years ago

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!

grivescorbett commented 6 years ago

Hi,

Thanks for writing in! This looks like it need to be updated. The syntax should be except errors.DfpReportError as e:

atlas-g0d commented 6 years ago

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 !

grivescorbett commented 6 years ago

Weird, feel free to post to the DFP API Forum and we can give you a hand with the implementation over there.

atlas-g0d commented 6 years ago

I got the code to work by doing the following:

  1. At line 57, change except errors.DfpReportError, e: to except errors.DfpReportErrorase:
  2. Make sure at line 57 - except errors.DfpReportError as e: stays under Try on line 54. Atom editor auto-adjusted the indention incorrectly so I had to move it back.
  3. All Print 'string' needs to be changed to Print('string')
  4. 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!