我正在尝试进行一个Google API调用,但在此处发现代码开头有一个错误:
import os
import argparse
import sys
from apiclient import sample_tools
from oauth2client import client
# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument(
'profile_id', type=int,
help='The ID of the profile to look up campaigns for')
# Authenticate and construct service.
service, flags = sample_tools.init(
argv[1:], 'dfareporting', 'v2.1', __doc__, os.path.abspath(os.path.dirname("__file__")), parents=[argparser],
scope=['https://www.googleapis.com/auth/dfareporting',
'https://www.googleapis.com/auth/dfatrafficking'])
if __name__ == '__main__':
main(sys.argv)
但是,sample_tools.init函数没有返回service和flags对象。我想我已经把它和argv论点a分开了
NameError: name 'argv' is not defined
任何帮助都将不胜感激!!!
您缺少
sys
:你要么需要
from sys import argv
并在任何地方使用argv
,要么需要import sys
并使用sys.argv
。我在任何地方也看不到main
函数,因此main(sys.argv)
也会导致名称错误相关问题 更多 >
编程相关推荐