Skip to content

Instantly share code, notes, and snippets.

@raihanba13
Created September 23, 2019 19:15
Show Gist options
  • Select an option

  • Save raihanba13/85131815ae9478aa239e95303b88a044 to your computer and use it in GitHub Desktop.

Select an option

Save raihanba13/85131815ae9478aa239e95303b88a044 to your computer and use it in GitHub Desktop.
import os
import sys
os.chdir('O:/python-code/gdrive_upload/')
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
#print(os.getcwd())
try:
gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'title': 'Hello.txt'}) # Create GoogleDriveFile instance with title 'Hello.txt'.
file1.SetContentString('Hello World!') # Set content of the file from given string.
file1.Upload()
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment