-1

I'm trying to use arguments from the console to use the --auth_local_webserver, --auth_host_port, this ones are required to get credentials from OAUTH2, but I can't make it work

I'm using the console this way python google\dev_appserver.py --auth_local_webserver=localhost --auth_host_port project/

My directory is this Project/app.main Project/Handlers/VideoTesting

And the VideoTesting is the one I'm using for handle the gflags, I really don't understand much of this and I have read a lot,

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 Answers1

0

The gflags.DEFINE... calls you show say you specify three flags:

  1. auth_local_webserver -- a boolean defaulting to true
  2. auth_host_name -- a string defaulting to "localhost"
  3. auth_host_port -- a list of integers defaulting to [8080, 8090]

But then you say you're using...:

--auth_local_webserver=localhost --auth_host_port

i.e, setting the boolean to a string (?!) and the list of integers to nothing (?!). I find this deeply confusing! What exactly is it, that you need to change from the three defaults above, and why? If the default values are fine just don't specify the flags and let them default, no?

Next, I'm not sure where the argument values are supposed to be getting parsed into the specified flags -- there's no such initialization in that mysteriously anonymous snippet of Python code (what .py file is it part of, precisely? and what other parts of that file are you hiding from us besides its name?) You must be hiding other parts because the one you show uses a debug barename it nowhere defines, it just springs out of the blue. And then once it's finally computed authorize_url it just ends abruptly without ever using that url...

Next, indentation is broken -- specifically, port_number = 0 is followed by a for port that's indented 2 spaces more; if you gave this code to the interpreter you'd get a SyntaxError.

Which reminds me, you never tell us what you expected and what you're observing instead -- "can't make it work" tells us nothing about how it's not working, so you're making it essentially impossible for us to help you beyond enumerating clear bugs and omissions in the anonymous snippet of code you do report. (And I've gone way over my quota in such enumeration about a single question so I'm going to stop here for now!)

So can you please edit your Q to clarify every one of these points...?!

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • Sorry for not be so careful of what I post, I figure another way of accomplish my objective, for the next time I'll be more clearly on what I want. Thanks for the comment – adriel1019 Feb 08 '15 at 19:46