Pandas / Google Analytics API 身份验证尝试抛出一个奇怪的 python 错误

Pandas / Google Analytics API authentication attempt throws me a weird python error

在我的 pandas/Google Analytics API 设置期间,我基本上按照 link:

中描述的进行了所有操作

http://blog.yhathq.com/posts/pandas-google-analytics.html

client_secrets.json 在 pandas/io 文件夹中。当我现在尝试执行

形式的语句时
>>>from pandas.io import ga
>>>df = ga.read_ga(metrics, dimensions, start_date)

出现以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "\Anaconda\lib\site-packages\pandas\io\ga.py", line 110, in read_ga
    reader = GAnalytics(**reader_kwds)
  File "\Anaconda\lib\site-packages\pandas\io\ga.py", line 179, in __init__
    self._service = self._init_service(secrets)
  File "\Anaconda\lib\site-packages\pandas\io\ga.py", line 191, in _init_service
    http = self.authenticate(secrets)
  File "\Anaconda\lib\site-packages\pandas\io\ga.py", line 151, in authenticate
    return auth.authenticate(flow, self.token_store)
  File "\Anaconda\lib\site-packages\pandas\io\auth.py", line 108, in authenticate
    credentials = tools.run(flow, storage)
AttributeError: 'module' object has no attribute 'run'

根据 yhat link,我的浏览器应该打开以进行身份​​验证。

注意:我没有为 "installed application" 创建客户端 ID,因为创建 ID 时菜单中没有此选项。相反,我选择了"other"。不过,这不应该是错误的原因。

第二个注意事项:我最近将 pandas 更新为 0.17.1。导入 pandas.io.ga 时,我收到了 .ga 模块已弃用的消息。此外,我手动安装了 gflags 模块,因为当我第一次尝试导入时需要它。io.ga。

向 Pandas 的所有者提交工单,将 pandas/io/auth.py 的(当前)第 108 行从 run() 更改为 run_flow(),或者自己进行修复并提交 PR。 (是的,如果 Google 刚刚创建 run_flow()run() 的别名就好了,但是正如你可以想象的那样,这不是这种变化的演变方式,所以我们必须忍受它。)

对于其他开发人员 运行 进入此错误:如果您有最新版本(as of Feb 2016) of the Google APIs Client Library for Python, just rename your call from tools.run() to tools.run_flow(), and you should be good-to-go. More about this change in a PSA (public service announcement) blogpost 我在 2015 年年中回信但定期更新以保持最新。

升级客户端库的最快方法是: pip install -U google-api-python-client # or pip3 for 3.x