我写了一个python脚本,每天将文件上传到我的Google Drive。当我从终端运行脚本时,它完美地工作。然而,当它获得通过的cronjob运行它失败并返回以下错误:Cronjob错误:无法找到client_secret.json文件Google App脚本
oauth2client.clientsecrets.InvalidClientSecretsError:(“打开文件时出错”,“client_secret.json”,“没有这样的文件或目录”,2)
问题是该文件位于我正在运行脚本的目录中。
这里是我的cronjob代码:
15 6 * * * python3 /home/pi/directory/file.py
这里是调用client_secret.json文件中的脚本:
def main():
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
SCOPES = 'https://www.googleapis.com/auth/drive.file'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store, flags) \
if flags else tools.run(flow, store)
DRIVE = build('drive', 'v3', http=creds.authorize(Http()))
任何意见或建议将是巨大的!
错误说 '错误打开文件', 'client_secret.json', '没有这样的文件或目录'。当它使用cron时,有必要小心文件的路径。那么如何改变client_secret.json文件的绝对路径呢?我不知道这是否会成为您的解决方案。对不起。 – Tanaike
我也尝试过,并没有奏效。 – Bokai
对不起,我无法为你提供帮助。 – Tanaike