Overwriting Google Drive API v3 Argparse in Python

后端 未结 2 1950
闹比i
闹比i 2020-12-19 20:22

I\'m trying to use the Google Drive API (v3) with Python to obtain and upload files to my Google Drive account.

I used this guide to setup my authentication: https:

相关标签:
2条回答
  • 2020-12-19 21:10

    Nevermind, I figured it out. hpaulj had it right.

    In the get_credentials() method, right before it called run_flow(), I simply had to add a line saying:

    flags=tools.argparser.parse_args(args=[])
    credentials=tools.run_flow(flow, store, flags)
    

    And at the beginning when I read the command line with my inputs, I simply used parser_known_flags() as hpaulj suggested!

    Thanks, shishy

    0 讨论(0)
  • 2020-12-19 21:16

    I think there have been other questions about argparse and the google api, but I haven't used the latter.

    Parsers are independent and can't be over written. But they all (as a default anyways) use sys.argv[1:]. So if your code runs before the other one, you can edit sys.argv to remove the extra strings. Using parse_known_args is a handy way of separating your arguments from ones the other parser(s) should use.

    Often the parser is invoked from a if __name__ block. That way imported modules don't do parsing, only ones used as scripts. But I don't if the google api makes this distinction.

    0 讨论(0)
提交回复
热议问题