title: Automating pydrive verification process
body: <p>I am trying to automate the <code>GoogleAuth</code> process when using the <code>pydrive</code> library (<a href="https://pypi.python.org/pypi/PyDrive" rel="noreferrer">https://pypi.python.org/pypi/PyDrive</a>).</p>
  
  <p>I've set up the pydrive and the google API such that my <code>secret_client.json</code> works but it requires web authentication for gdrive access every time i run my script:</p>
  
  <pre><code>from pydrive.auth import GoogleAuth
  from pydrive.drive import GoogleDrive
  
  gauth = GoogleAuth()
  gauth.LocalWebserverAuth()
  
  drive = GoogleDrive(gauth)
  
  textfile = drive.CreateFile()
  textfile.SetContentFile('eng.txt')
  textfile.Upload()
  print textfile
  
  drive.CreateFile({'id':textfile['id']}).GetContentFile('eng-dl.txt')
  </code></pre>
  
  <p><code>eng.txt</code> is just a textfile. Moreover when I try to use the above script while I am logged into another account. <strong>It doesn't upload the <code>eng.txt</code> into my gdrive that generated the <code>secret_client.json</code> but the account that was logged in when I authorize the authentication</strong></p>
  
  <p>From the previous post, I've tried the following to automate the verification process but it's giving error messages: </p>
  
  <pre><code>import base64, httplib2
  from pydrive.auth import GoogleAuth
  from pydrive.drive import GoogleDrive
  
  from apiclient.discovery import build
  from oauth2client.client import SignedJwtAssertionCredentials
  from pydrive.auth import GoogleAuth
  from pydrive.drive import GoogleDrive
  
  #gauth = GoogleAuth()
  #gauth.LocalWebserverAuth()
  
  # from google API console - convert private key to base64 or load from file
  id = "464269119984-j3oh4aj7pd80mjae2sghnua3thaigugu.apps.googleusercontent.com"
  key = base64.b64decode('COaV9QUlO1OdqtjMiUS6xEI8')
  
  credentials = SignedJwtAssertionCredentials(id, key, scope='https://www.googleapis.com/auth/drive')
  credentials.authorize(httplib2.Http())
  
  gauth = GoogleAuth()
  gauth.credentials = credentials
  
  drive = GoogleDrive(gauth)
  
  drive = GoogleDrive(gauth)
  
  textfile = drive.CreateFile()
  textfile.SetContentFile('eng.txt')
  textfile.Upload()
  print textfile
  
  drive.CreateFile({'id':textfile['id']}).GetContentFile('eng-dl.txt')
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/alvas/git/SeedLing/cloudwiki.py", line 29, in &lt;module&gt;
      textfile.Upload()
    File "/usr/local/lib/python2.7/dist-packages/pydrive/files.py", line 216, in Upload
      self._FilesInsert(param=param)
    File "/usr/local/lib/python2.7/dist-packages/pydrive/auth.py", line 53, in _decorated
      self.auth.Authorize()
    File "/usr/local/lib/python2.7/dist-packages/pydrive/auth.py", line 422, in Authorize
      self.service = build('drive', 'v2', http=self.http)
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper
      return wrapped(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/apiclient/discovery.py", line 192, in build
      resp, content = http.request(requested_url)
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper
      return wrapped(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 475, in new_request
      self._refresh(request_orig)
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 653, in _refresh
      self._do_refresh_request(http_request)
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 677, in _do_refresh_request
      body = self._generate_refresh_request_body()
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 861, in _generate_refresh_request_body
      assertion = self._generate_assertion()
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 977, in _generate_assertion
      private_key, self.private_key_password), payload)
    File "/usr/local/lib/python2.7/dist-packages/oauth2client/crypt.py", line 131, in from_string
      pkey = crypto.load_pkcs12(key, password).get_privatekey()
  OpenSSL.crypto.Error: [('asn1 encoding routines', 'ASN1_get_object', 'header too long')]
  </code></pre>
  
  <p>My authentication on gdrive api looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/7grL4.png" alt="enter image description here"></p>
  
  <p><strong>How could I use pydrive such that I do not need to authenticate everytime I use it?</strong></p>
  
  <p><strong>How to allow automatic authentication such that the python script using the pydrive script will only upload to the account that generated the <code>secret_client.json</code> and not the currently logged on account on the internet browser?</strong></p>