python - '.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。这是我使用的第一个文件。请让我知道如何解决它。
解决方案
推荐阅读
- swift - UnsafeMutablePointer.pointee 和 didSet 属性
- c# - .NET webforms 数据库连接中的存储库
- django - 我们可以使用 Django 子查询进行算术运算吗?
- regex - perl 正则表达式,用于捕获 tic 标记之间的子字符串
- javascript - 为什么对象使用`Symbol.iterator`,而不仅仅是`iterator`
- batch-file - 如何按顺序合并文件
- c# - Xamarin - 为文本视图设置背景颜色和边框
- python - 脚本问题将配置复制到文件中?
- typescript - 是否可以仅在函数调用中推断出一些泛型?
- javascript - 仅使用 javascript 条件语句返回更改