mburke05
mburke05

Reputation: 1471

Pandas: noauth_local_webserver

I haven't used io within pandas to access google analytic's API for a few weeks but it had been working fine to my knowledge historically without hiccups. I ran it again today and it looks as though the tools.run syntax is deprecated, so I made a pull and replaced tools.py with this update and I've changed to auth.py within pandas to be:

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

I have a feeling my usage of FLAGS there is incorrect.

Any help? Thanks!

Here's my code and the error:

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]})

The error thrown up:

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

Upvotes: 3

Views: 834

Answers (1)

Josh J
Josh J

Reputation: 6893

I did a little digging and you are correct in your assumption that the usage of FLAGS is incorrect. The docstring for tools.run_flow() states:

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

The quick-n-dirty fix would be something like this:

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

I believe a more robust solution would be for the maintainers of pandas.io to update it to the new workflow if tools.run is really deprecated.

Upvotes: 1

Related Questions