Jupyter Notebook中的Google-oauth [英] Google-oauth inside Jupyter Notebook

查看:101
本文介绍了Jupyter Notebook中的Google-oauth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google oauth2client,示例中的代码为:

I am using Google oauth2client and the code from sample is:

flags = argparser.parse_args()
credentials = run_flow(flow, storage, flags)

所有功能都可以在Python交互式或IDE中使用,但是如果我尝试使用Jupiter Notebook中的代码,则会出现异常.

All works in Python interactive or IDE but if I am trying to use the code from Jupiter Notebook I got an exception.

在Jupiter Noteboo内部,我正在尝试简单:

Inside Jupiter Noteboo I am trying simple:

    from oauth2client.tools import argparser
    argparser.parse_args()

and got:

usage: __main__.py [--auth_host_name AUTH_HOST_NAME]
                   [--noauth_local_webserver]
                   [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
                       [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
    __main__.py: error: unrecognized arguments: -f /run/user/1000/jupyter/kernel-c9aa5199-fcea-4884-8e5f-a004c66a733e.json

SystemExit                                Traceback (most recent call last)
<ipython-input-3-d141fc7aebe0> in <module>()
----> 1 argparser.parse_args()

/usr/lib/python3.5/argparse.py in parse_args(self, args, namespace)
   1736         if argv:
   1737             msg = _('unrecognized arguments: %s')
-> 1738             self.error(msg % ' '.join(argv))
   1739         return args
   1740 

/usr/lib/python3.5/argparse.py in error(self, message)
   2392         self.print_usage(_sys.stderr)
   2393         args = {'prog': self.prog, 'message': message}
-> 2394         self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

/usr/lib/python3.5/argparse.py in exit(self, status, message)
   2379         if message:
   2380             self._print_message(message, _sys.stderr)
-> 2381         _sys.exit(status)
   2382 
   2383     def error(self, message):

SystemExit: 2

推荐答案

摘自 ArgumentParser.parse_args() ,默认情况下,参数字符串取自sys.argv [...]".在这种情况下,sys.argv命令行参数是创建Jupyter笔记本服务器进程的参数.解决方法是,假设您不需要使用任何标志,则可以替换

From the documentation for ArgumentParser.parse_args(), "By default, the argument strings are taken from sys.argv [...]". In this case, the sys.argv command-line arguments are those that created the Jupyter notebook server process. As a workaround, assuming you don't need to use any flags, you can replace

flags = argparser.parse_args()

使用

flags = argparser.parse_args([])

您可以像这样在提供的列表中将标志添加为字符串:

You can add flags as strings in the provided list like this:

flags = argparser.parse_args(['--auth_host_name=example.org', '--auth_host_port=1234'])

这篇关于Jupyter Notebook中的Google-oauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆