NameError: name 'argv' is undefined

I am trying to make a google API call and get an error with the start of the code found here:

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)
    '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],

if __name__ == '__main__':


However, the sample_tools.init function does not return the service object and flags. I think I have isolated it to the argument argv a

NameError: name 'argv' is not defined


Any help would be much appreciated.


source to share

1 answer

You are missing sys




You either need to from sys import argv

, or use it argv

everywhere, or import sys

like yours and use sys.argv

. I also don't see the function main

anywhere, so main(sys.argv)

will raise NameError as well



All Articles