gpt4 book ai didi

python - Pandas :noauth_local_webserver

转载 作者:太空宇宙 更新时间:2023-11-04 05:44:39 24 4
gpt4 key购买 nike

我已经有几周没有在 pandas 中使用 io 来访问 google analytic 的 API,但据我所知,它在历史上一直运行良好,没有出现问题。我今天再次运行它,它看起来好像 tools.run 语法已被弃用,所以我做了一个拉动并将 tools.py 替换为 this update我已经将 pandas 中的 auth.py 更改为:

def authenticate(flow, storage=None):
"""
Try to retrieve a valid set of credentials from the token store if possible
Otherwise use the given authentication flow to obtain new credentials
and return an authenticated http object

Parameters
----------
flow : authentication workflow
storage: token storage, default None
"""
http = httplib2.Http()

# Prepare credentials, and authorize HTTP object with them.
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run_flow(flow, storage, FLAGS)

http = credentials.authorize(http)
return http

我感觉我对 FLAGS 的使用不正确。

有什么帮助吗?谢谢!

这是我的代码和错误:

df = ga.read_ga(
account_id = id,
profile_id = profile,
property_id = property,
metrics = ['transactionRevenue', 'transactions'],
dimensions = ['transactionId', 'city', 'region', 'date', 'hour', 'minute', 'cityId'],
start_date = "2015-07-11",
end_date = "2015-07-16",
index_col = 0,
parse_dates = {'new_date': [3,4,5]})

抛出的错误:

C:\Users\mburke\AppData\Local\Continuum\Anaconda64\lib\site-packages\pandas\io\auth.py in authenticate(flow, storage)
106 credentials = storage.get()
107 if credentials is None or credentials.invalid:
--> 108 credentials = tools.run_flow(flow, storage, FLAGS)
109
110 http = credentials.authorize(http)

C:\Users\mburke\AppData\Local\Continuum\Anaconda64\lib\site-packages\oauth2client\util.pyc in positional_wrapper(*args, **kwargs)
140 else: # IGNORE
141 pass
--> 142 return wrapped(*args, **kwargs)
143 return positional_wrapper
144

C:\Users\mburke\AppData\Local\Continuum\Anaconda64\lib\site-packages\oauth2client\tools.pyc in run_flow(flow, storage, flags, http)
148 logging.getLogger().setLevel(getattr(logging, flags.logging_level))
--> 149 if not flags.noauth_local_webserver:
150 success = False
151 port_number = 0

C:\Users\mburke\AppData\Local\Continuum\Anaconda64\lib\site-packages\python_gflags-2.0-py2.7.egg\gflags.pyc in __getattr__(self, name)
1057 fl = self.FlagDict()
1058 if name not in fl:
-> 1059 raise AttributeError(name)
1060 return fl[name].value
1061

AttributeError: noauth_local_webserver

最佳答案

我做了一些挖掘,您认为 FLAGS 的用法不正确的假设是正确的。 docstring for tools.run_flow()状态:

flags: ``argparse.Namespace``, The command-line flags. This is the
object returned from calling ``parse_args()`` on
``argparse.ArgumentParser`` as described above.

快速解决方案应该是这样的:

credentials = tools.run_flow(flow, storage, tools.argparser.parse_args([]))

我相信如果 tools.run 真的被弃用,pandas.io 的维护者将其更新为新的工作流程是一个更强大的解决方案。

关于python - Pandas :noauth_local_webserver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32750233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com