Pandas / Google Analytics API 身份驗證嘗試給我帶來了一個奇怪的 python 錯誤 (Pandas / Google Analytics API authentication attempt throws me a weird python error)


問題描述

Pandas / Google Analytics API 身份驗證嘗試給我帶來了一個奇怪的 python 錯誤 (Pandas / Google Analytics API authentication attempt throws me a weird python error)

在我的 pandas/Google Analytics API 設置過程中,我基本上按照此鏈接中的說明進行了所有操作:

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鏈接,我的瀏覽器應該打開以進行身份驗證。

注意:我沒有為“已安裝的應用程序”創建客戶端 ID,因為我在創建 ID 時在菜單中沒有這個選項。相反,我選擇了“其他”。不過,這不應該是錯誤的原因。

第二個提示:我最近將我的 pandas 更新到了 0.17.1。導入 pandas.io.ga 時,我收到 .ga 模塊已棄用的消息。此外,我手動安裝了 gflags 模塊,因為當我第一次嘗試導入 .io.ga 時需要它。


參考解法

方法 1:

Either file a ticket with the owners of Pandas to change (currently) line 108 of pandas/io/auth.py from run() to run_flow(), or make the fix yourself and file a PR. (Yes, it would've been nice if Google had just made run_flow() and alias of run(), but as you can imagine, this is not how this change evolved, so we have to live with it.)

For other developers running into this error: If you have the latest version (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 I wrote back in mid‑2015 but update periodically to stay current.

The fastest way to upgrade your Client Library is with: pip install ‑U google‑api‑python‑client # or pip3 for 3.x

(by mmontanawescpy)

參考文件

  1. Pandas / Google Analytics API authentication attempt throws me a weird python error (CC BY‑SA 2.5/3.0/4.0)

#google-analytics-api #google-api #Python #pandas #google-analytics






相關問題

使用C#的Google Analytics(分析)訪問 (Google Analytics Access with C#)

嘗試安裝新的 Google Analytics 3.0 Beta 時出現鏈接器錯誤 (Linker errors when trying to install new Google Analytics 3.0 Beta)

Google Analytics:數據導入和每日上傳的區別 (Google Analytics: Difference between Data Import & Daily upload)

Google Reporting API for Analytics 庫依賴項 (Google Reporting API for Analytics library dependencies)

將 Google Analytics 權限分配給整個公司域 (Assign Google Analytics Permission To Whole Company Domain)

將 google-api-client 0.9.pre3 集成到 dashing 後的 NoMethodError (NoMethodError after integrating google-api-client 0.9.pre3 in dashing)

谷歌分析:在我的網站上顯示數據時,我可以使用自定義維度名稱而不是索引嗎 (Google analytics : Can I use custom dimension name instead of index while showing data on Report On my Site)

Pandas / Google Analytics API 身份驗證嘗試給我帶來了一個奇怪的 python 錯誤 (Pandas / Google Analytics API authentication attempt throws me a weird python error)

如何訪問行為流數據?(在應用程序 Google Analytics 帳戶上。) (How to access Behavior Flow data? (on a Application Google Analytics Account.))

如何在 Google Analytics 的一份報告中單獨細分指標? (How to individually segment metrics in one report in Google Analytics?)

Python - 問題使用循環每天得到 (Python - Problem use loops to get day by day)

我想要在 PHP 中使用 orderBy 和 Filters 的 Google Analytics Data API (GA4) 示例代碼 (I want a sample code for Google Analytics Data API (GA4) in PHP using orderBy and Filters)







留言討論