2017-08-30 89 views
0

我写了一个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())) 

任何意见或建议将是巨大的!

+0

错误说 '错误打开文件', 'client_secret.json', '没有这样的文件或目录'。当它使用cron时,有必要小心文件的路径。那么如何改变client_secret.json文件的绝对路径呢?我不知道这是否会成为您的解决方案。对不起。 – Tanaike

+0

我也尝试过,并没有奏效。 – Bokai

+0

对不起,我无法为你提供帮助。 – Tanaike

回答

0

您必须使用文件客户端_secret.json的绝对路径。一旦我更新了所有工作的路径。

更改: 流速= client.flow_from_clientsecrets( 'client_secret.json',SCOPES)

商店= file.Storage( 'storage.json')

flow = client.flow_from_clientsecrets('/ path/to/file/client_secret.json',SCOPES)

and

商店= file.Storage( '/路径/到/文件/ storage.json')

相关问题