title: How to download a file from Google Drive using Python and the Drive API v3
body: <p>I have tried downloading file from Google Drive to my local system using python script but facing a "forbidden" issue while running a Python script. The script is as follows:</p>
  
  <pre><code>import requests
  
  url = "https://www.googleapis.com/drive/v3/files/1wPxpQwvEEOu9whmVVJA9PzGPM2XvZvhj?alt=media&amp;export=download"
  
  querystring = {"alt":"media","export":"download"}
  
  headers = {
      'Authorization': "Bearer TOKEN",
  
      'Host': "www.googleapis.com",
      'Accept-Encoding': "gzip, deflate",
      'Connection': "keep-alive",
      }
  
  response = requests.request("GET", url, headers=headers, params=querystring)
  
  print(response.url)
  #
  import wget
  import os
  from os.path import expanduser
  
  
  myhome = expanduser("/home/sunarcgautam/Music")
  ### set working dir
  os.chdir(myhome)
  
  url = "https://www.googleapis.com/drive/v3/files/1wPxpQwvEEOu9whmVVJA9PzGPM2XvZvhj?alt=media&amp;export=download"
  print('downloading ...')
  wget.download(response.url)
  </code></pre>
  
  <p>In this script, I have got forbidden issue. Am I doing anything wrong in the script?</p>
  
  <p>I have also tried another script that I found on a Google Developer page, which is as follows:</p>
  
  <pre><code>import auth
  import httplib2
  SCOPES = "https://www.googleapis.com/auth/drive.scripts"
  CLIENT_SECRET_FILE = "client_secret.json"
  APPLICATION_NAME = "test_Download"
  authInst = auth.auth(SCOPES, CLIENT_SECRET_FILE, APPLICATION_NAME)
  credentials = authInst.getCredentials()
  http = credentials.authorize(httplib2.Http())
  drive_serivce = discovery.build('drive', 'v3', http=http)
  
  file_id = '1Af6vN0uXj8_qgqac6f23QSAiKYCTu9cA'
  request = drive_serivce.files().export_media(fileId=file_id,
                                               mimeType='application/pdf')
  fh = io.BytesIO()
  downloader = MediaIoBaseDownload(fh, request)
  done = False
  while done is False:
      status, done = downloader.next_chunk()
      print ("Download %d%%." % int(status.progress() * 100))
  </code></pre>
  
  <p>This script gives me a <strong>URL mismatch error</strong>.</p>
  
  <p>So what should be given for redirect URL in Google console credentials? or any other solution for the issue? Do I have to authorise my Google console app from Google in both the script? If so, what will the process of authorising the app because I haven't found any document regarding that.</p>