0

I successfully uploaded the file to google drive as follows https://pythonhosted.org/PyDrive/quickstart.html, https://pythonhosted.org/PyDrive/oauth.html#automatic-and-custom-authentication-with-settings-yaml

however, cron job couldn't make upload the file to google drive through execute the same file.

here's my setting

download client_secrets.json

quickstart.py

from my drive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.CommandLineAuth() # gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
.
.
def create_csv()
.
.
def upload()
.
.

settings.yaml

client_config_backend: settings
client_config:
  client_id: ***
  client_secret: ***
save_credentials: True
save_credentials_backend: file
save_credentials_file: credentials.json

get_refresh_token: True

oauth_scope:
  - https://www.googleapis.com/auth/drive.file
  - https://www.googleapis.com/auth/drive.install

why cron job doesn't work? because of the OAuth?

thanks

  • Welcome to stack overflow !!! So, the way you want to find cron problems is to implement logging to a file https://docs.python.org/3.7/howto/logging.html. Put a try/except around the entire code and log the error. If you have more code than shown here, drop some logging in the code to check the values of things. I suspect you have a permissions issue. – SteveJ Dec 31 '18 at 01:57
  • [2018-12-31 09:33:02,160][ERROR]Invalid client secrets file ('Error opening file', 'client_secrets.json', 'No such file or directory', 2) ---|--- [2018-12-31 09:33:02,291][ERROR]global name 'drive' is not defined – user6578430 Dec 31 '18 at 09:35
  • I fix this problem by modifying cron. before : 0 0 * * * /${PATH}/script.sh after : 0 0 * * * cd /${PATH}/ && /${PATH}/script.sh – user6578430 Dec 31 '18 at 10:29

1 Answers1

0

You might want to try:

Forking https://github.com/klanjabrik/Backup-To-Google-Drive (Python 3) from original repo https://github.com/bachvtuan/Backup-To-Google-Drive (Python 2)

Meirza
  • 1,318
  • 10
  • 15