GAE中的gflags和localhost

时间:2015-02-07 21:19:43

标签: python google-app-engine localhost gflags

我正在尝试使用控制台中的参数来使用 --auth_local_webserver, - auth_host_port,这些都需要得到 来自OAUTH2的凭据,但我无法使其正常工作

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

我的目录是这样的 项目/ app.main 项目/处理程序/ VideoTesting

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.'))

1 个答案:

答案 0 :(得分:0)

您显示的gflags.DEFINE...来电表示您指定了三个标记:

  1. auth_local_webserver - 布尔值默认为true
  2. auth_host_name - 默认为“localhost”的字符串
  3. auth_host_port - 默认为[8080,8090]的整数列表
  4. 但是你说你正在使用......:

    --auth_local_webserver=localhost --auth_host_port
    

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

    接下来,我不确定参数值应该被解析到指定标志的哪个位置 - 在Python代码的神秘匿名片段中没有这样的初始化(.py文件是它的一部分,确切地说?除了它的名字之外你还隐藏了那个文件的其他部分?)你必须隐藏其他部分,因为你展示的部分使用了debug裸名,它无处可定义,它只是突然出现了蓝色。然后,一旦它最终被计算authorize_url,它就会突然结束,而不会使用该网址...

    接下来,缩进被破坏 - 具体而言,port_number = 0之后是for port,其中缩进了2个空格;如果您将此代码提供给解释器,则会得到SyntaxError

    这让我想起,你永远不会告诉我们你的期望和你所观察到的 - “无法使其发挥作用”告诉我们没有关于它如何不起作用,所以你'除了在您报告的匿名代码片段中列举明确的错误和遗漏之外,我们基本上无法帮助您。 (而且我已经在一个单一问题的列举中超过了我的配额,所以我现在要停在这里!)

    那么请你编辑你的Q以澄清这些要点......?