【问题标题】:gflags and localhost in GAEGAE 中的 gflags 和 localhost
【发布时间】:2015-04-07 21:05:50
【问题描述】:

我正在尝试使用控制台中的参数来使用 --auth_local_webserver, --auth_host_port, 获取这些是必须的 来自 OAUTH2 的凭据,但我无法使其工作

我正在以这种方式使用控制台 python google\dev_appserver.py --auth_local_webserver=localhost --auth_host_port 项目/

我的目录是这个 项目/app.main 项目/处理程序/视频测试

而 VideoTesting 是我用来处理 gflags 的,我真的不太了解,我已经阅读了很多,

if FLAGS.auth_local_webserver:    

  success = False
  port_number = 0
    for port in FLAGS.auth_host_port:
      port_number = port
      debug.response.write(str(port_number))

      try:
        httpd = ClientRedirectServer((FLAGS.auth_host_name, port),
                                 ClientRedirectHandler)
        debug.response.write('what')
      except socket.error, e:

        pass
      else:
        success = True
        break
    FLAGS.auth_local_webserver = success
  if FLAGS.auth_local_webserver:
     oauth_callback = 'http://%s:%s/' % (FLAGS.auth_host_name, port_number)
  else:
     oauth_callback = 'oob'
  authorize_url = flow.step1_get_authorize_url(oauth_callback)

FLAGS = gflags.FLAGS

gflags.DEFINE_boolean('auth_local_webserver', True,
                  ('Run a local web server to handle redirects during '
                   'OAuth authorization.'))

gflags.DEFINE_string('auth_host_name', 'localhost',
                 ('Host name to use when running a local web server to '
                  'handle redirects during OAuth authorization.'))

gflags.DEFINE_multi_int('auth_host_port', [8080, 8090],
                    ('Port to use when running a local web server to '
                     'handle redirects during OAuth authorization.'))

【问题讨论】:

    标签: python google-app-engine localhost gflags


    【解决方案1】:

    您显示的gflags.DEFINE... 调用说您指定了三个标志:

    1. auth_local_webserver -- 默认为 true 的布尔值
    2. auth_host_name -- 默认为“localhost”的字符串
    3. auth_host_port -- 默认为 [8080, 8090] 的整数列表

    但是你说你正在使用...:

    --auth_local_webserver=localhost --auth_host_port
    

    即将布尔值设置为字符串 (?!) 并将整数列表设置为空 (?!)。我觉得这很令人困惑!究竟是什么,您需要从上面的三个默认值中进行更改,为什么?如果默认值没问题,就不要指定标志并让它们默认,不是吗?

    接下来,我不确定参数值应该在哪里解析为指定的标志——在 Python 代码的神秘匿名 sn-p 中没有这样的初始化(.py 文件是它的一部分,确切地说?除了它的名字之外,你还向我们隐藏了该文件的哪些其他部分?)你必须隐藏其他部分,因为你展示的那个使用了一个没有任何定义的debugbarename,它只是突然出现。然后,一旦最终计算出authorize_url,它就会突然结束,而没有使用过那个 url...

    接下来,缩进被打破——具体来说,port_number = 0 后面跟着一个缩进 2 个空格的 for port;如果您将此代码提供给解释器,您将获得SyntaxError

    这提醒了我,你从来没有告诉我们你的期望和你正在观察什么——“不能让它工作”告诉我们没有它是如何不工作的,所以你'除了列举您报告的匿名 sn-p 代码中的明显错误和遗漏之外,我们基本上无法为您提供帮助。 (而且我在这样一个问题的枚举中已经超出了我的配额,所以我现在要在这里停下来!)

    那么您能否编辑您的 Q 以澄清这些要点...?!

    【讨论】:

    • 对不起,我发布的内容没有那么小心,我想了另一种方法来实现我的目标,下次我会更清楚我想要什么。感谢您的评论
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多