首页 > 解决方案 > '.py' 文件在设置 cronjob 后不会自动执行。虽然它在手动执行时运行。这将如何解决?

问题描述

'.py' 文件中的几行代码:

#pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials

from google.oauth2 import service_account

SERVICE_ACCOUNT_FILE = 'projectname.json'
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']

creds = None
creds = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

# The spreadsheet ID. Spreadsheet ID is not important for the example.
SAMPLE_SPREADSHEET_ID = 'abcd'

service = build('sheets', 'v4', credentials=creds)

# Call the Sheets API
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
                                range='East!A2:F537').execute()
values = result.get('values', [])
values

但是,当我在 Jupyter 笔记本中手动运行它时,它会执行

%run Lockdown_Bifurcation_Gsheet_Jishnu.py

Lockdown_Bifurcation_Gsheet_Jishnu.py 是“.py”文件的名称

我的cornjob设置为:

00 03 * * * python3 LMOA_cron/Lockdown_Bifurcation_Gsheet_Jishnu.py >> LMOA_cron/logs/Lockdown_Bifurcation_Gsheet_Jishnu.log

我已经在终端中设置了工作:

https://orgname.com/user/adminhub/terminals/36

它没有被执行的原因可能是什么?还有其他文件会自动触发。我没有在这些文件中使用 Gsheets API。这是我使用的第一个文件。请让我知道如何解决它。

标签: pythonautomationjupyter-notebookcron

解决方案


推荐阅读