我在这里显示的示例代码(python版本)中遇到了问题:
我在这点上遇到了问题:
except TypeError, error:
# Handle errors in constructing a query.
print 'There was an error in constructing your query : %s' % error
except HttpError, error:
# Handle API errors.
print ('There was an API error : %s : %s' %
(error.resp.status, error.resp.reason))错误:
except TypeError, error:
^
SyntaxError: invalid syntax我刚开始使用Python,但上面提到的链接中的示例代码似乎使用的是python2,所以我不得不做一些修改(比如用括号封装每个“打印”)。会不会是这样的东西?我找不到另一种方法来写这些。
我敢打赌,这一定是很愚蠢的事情,但我不能完全修复它!在此之前,非常感谢您。
发布于 2019-04-16 18:37:58
你可以使用the tool 2to3来做这类事情。以下是运行Python后示例代码片段,其中example.py是一个文件,其中包含您提供的那个链接处的python示例代码。
try:
audiences = analytics.management().remarketingAudience().list(
accountId='123456',
webPropertyId='UA-123456-1'
).execute()
except TypeError as error:
# Handle errors in constructing a query.
print('There was an error in constructing your query : %s' % error)
except HttpError as error:
# Handle API errors.
print(('There was an API error : %s : %s' %
(error.resp.status, error.resp.reason)))
...在Python3中,HttpError, error不是except之后的有效语法
https://stackoverflow.com/questions/55692421
复制相似问题