title: python argparse - pass values WITHOUT command line
body: <p>I think I'm not understanding something basic about python's argparse.</p>
  
  <p>I am trying to use the Google YouTube API for python script, but I am not understanding how to pass values to the script without using the command line.</p>
  
  <p>For example, <a href="https://developers.google.com/youtube/v3/docs/videos/insert" rel="noreferrer">here</a> is the example for the API.  The examples on github and elsewhere show this example as being called from the command line, from where the argparse values are passed when the script is called.</p>
  
  <p>I don't want to use the command line.  I am building an app that uses a decorator to obtain login credentials for the user, and when that user wants to upload to their YouTube account, they submit a form which will then call this script and have the argparse values passed to it.</p>
  
  <p>How do I pass values to argparser (see below for portion of code in YouTube upload API script) from another python script?</p>
  
  <pre><code>if __name__ == '__main__':
      argparser.add_argument("--file", required=True, help="Video file to upload")
      argparser.add_argument("--title", help="Video title", default="Test Title")
      argparser.add_argument("--description", help="Video description",
          default="Test Description")
      argparser.add_argument("--category", default="22",
          help="Numeric video category. " +
              "See https://developers.google.com/youtube/v3/docs/videoCategories/list")
      argparser.add_argument("--keywords", help="Video keywords, comma separated",
          default="")
      argparser.add_argument("--privacyStatus", choices=VALID_PRIVACY_STATUSES,
          default=VALID_PRIVACY_STATUSES[0], help="Video privacy status.")
      args = argparser.parse_args()
  
      if not os.path.exists(args.file):
          exit("Please specify a valid file using the --file= parameter.")
  
      youtube = get_authenticated_service(args)
      try:
          initialize_upload(youtube, args)
      except HttpError, e:
          print "An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)
  </code></pre>
  
  <hr>
  
  <p>EDIT: Per request, here is the traceback for the 400 Error I am getting using either the standard method to initialize a dictionary or using argparse to create a dictionary.  I thought I was getting this due to badly formed parameters, but perhaps not:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
      rv = self.handle_exception(request, response, e)
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
      rv = self.router.dispatch(request, response)
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
      return route.handler_adapter(request, response)
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
      return handler.dispatch()
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
      return self.handle_exception(e, self.app.debug)
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
      return method(*args, **kwargs)
    File "C:\Users\...\testapp\oauth2client\appengine.py", line 796, in setup_oauth
      resp = method(request_handler, *args, **kwargs)
    File "C:\Users\...\testapp\testapp.py", line 116, in get
      resumable_upload(insert_request)
    File "C:\Users\...\testapp\testapp.py", line 183, in resumable_upload
      status, response = insert_request.next_chunk()
    File "C:\Users\...\testapp\oauth2client\util.py", line 129, in positional_wrapper
      return wrapped(*args, **kwargs)
    File "C:\Users\...\testapp\apiclient\http.py", line 874, in next_chunk
      return self._process_response(resp, content)
    File "C:\Users\...\testapp\apiclient\http.py", line 901, in _process_response
      raise HttpError(resp, content, uri=self.uri)
  HttpError: &lt;HttpError 400 when requesting https://www.googleapis.com/upload/youtube/v3/videos?alt=json&amp;part=status%2Csnippet&amp;uploadType=resumable returned "Bad Request"&gt;
  </code></pre>