1

The oauth2client library defines a method called run_flow. From run_flow's documentation, run_flow allows certain CLI flags to be specified through an arg parser internal to oauth's tool's package. These flags are:

--auth_host_name (string, default: localhost)
Host name to use when running a local web server to handle redirects during OAuth authorization.

--auth_host_port (integer, default: [8080, 8090])
Port to use when running a local web server to handle redirects during 
OAuth authorization. Repeat this option to specify a list of values.

--[no]auth_local_webserver (boolean, default: True)
Run a local web server to handle redirects during OAuth authorization.

However, these flags are an issue for me because my program makes extensive use of flags I defined myself through a different argument parser instance, and those flags conflict with oauth's. This collision generates this error:

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: --students student_names_here

I looked at using tools.init from this similar stack overflow post: Using Argparse with Google Admin API

I couldn't find tools.init documentation, and so it may be deprecated. How can I use my cli flags without them conflicting with oauth run_flow's internal argparser?

wfehrn
  • 105
  • 1
  • 11
  • The way you are calling this script, runs both Google's own `parser` as well as your own. You can use `parse_known_args` to skip arguments that you don't handle, but you can't force the Google parser to do that. You need to find a way of using the Google code without it running its parser. I think there are newer SO questions about using/bypassing Google API parsers. – hpaulj Jul 18 '17 at 17:27
  • 1
    https://stackoverflow.com/questions/39886041/overwriting-google-drive-api-v3-argparse-in-python might be useful – hpaulj Jul 18 '17 at 19:04

0 Answers0