错误:argparse参数太少

时间:2017-03-22 08:03:58

标签: python json firebase

我尝试使用python脚本将json文件导入firebase。然后我在Github遇到了类似的脚本。我在替换所需参数后尝试运行它。我得到的论点错误太少了。如果您想参考

,这是Github项目

https://github.com/firebase/firebase-streaming-import

我正在运行的代码片段如下。我使用IDLE来运行程序。提前致谢

argParser = argparse.ArgumentParser(description="Import a large json file into a Firebase via json Streaming.\
                                                 Uses HTTP PATCH requests.  Two-pass script, run once normally,\
                                                 then again in --priority_mode.")
argParser.add_argument('firebase_url', help="Specify the Firebase URL (e.g. https://test.firebaseio.com/dest/path/).")
argParser.add_argument('json_file', help="The JSON file to import.")
argParser.add_argument('-a', '--auth', help="Optional Auth token if necessary to write to Firebase.")
argParser.add_argument('-t', '--threads', type=int, default=8, help='Number of parallel threads to use, default 8.')
argParser.add_argument('-s', '--silent', action='store_true',
                       help="Silences the server response, speeding up the connection.")
argParser.add_argument('-p', '--priority_mode', action='store_true',
                       help='Run this script in priority mode after running it in normal mode to write all priority values.')

main(argParser.parse_args())

1 个答案:

答案 0 :(得分:2)

因为你不能用IDLE中的terminal / cmd之类的参数来解析参数。尝试解析args:args = argParser.parse_args(['URL','FILE_PATH'])

import argparse

argParser = argparse.ArgumentParser(description="Import a large json file into a Firebase via json Streaming.\
                                                 Uses HTTP PATCH requests.  Two-pass script, run once normally,\
                                                 then again in --priority_mode.")
argParser.add_argument('firebase_url', help="Specify the Firebase URL (e.g. https://test.firebaseio.com/dest/path/).")
argParser.add_argument('json_file', help="The JSON file to import.")
argParser.add_argument('-a', '--auth', help="Optional Auth token if necessary to write to Firebase.")
argParser.add_argument('-t', '--threads', type=int, default=8, help='Number of parallel threads to use, default 8.')
argParser.add_argument('-s', '--silent', action='store_true',
                       help="Silences the server response, speeding up the connection.")
argParser.add_argument('-p', '--priority_mode', action='store_true',
                       help='Run this script in priority mode after running it in normal mode to write all priority values.')

args = argParser.parse_args(['URL','FILE_PATH'])

print(args)

main(args)

输出:

Namespace(auth=None, firebase_url='URL', json_file='FILE_PATH', priority_mode=False, silent=False, threads=8)