2017-08-30 49 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')

相關問題