A few days ago, a script for a scheduled task that worked with no problems for months, stopped working. I tried to understand what's going on and added comments to my script. So, now it goes like this
print("Start")
import time
from IPython.display import display, Markdown
from datetime import datetime, timedelta, date
from pathlib import Path
import argparse
import yaml
print("Import 1")
import shutil
import sys
import os
print("Import 2")
# Change the current directory to where the script is located.
script_dir = os.path.dirname(os.path.abspath(__file__))
# Change the current working directory
os.chdir(script_dir)
print(f"Current working directory: {os.getcwd()}")
# Add the parent directory of the current directory to Python path
parent_dir = os.path.dirname(os.getcwd())
if parent_dir not in sys.path:
sys.path.append(parent_dir)
from utils.ai_wrapper import AIWrapper
from utils.news_scraper import NewsReader, NewsConfig, NewsListFilter, ImageDataExtractor, DateTimeHandler, NavigationManager
etc.
But then in the log I am getting:
WARNING:utils.ai_wrapper:Attempt 1 failed: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.0: all messages must have non-empty content except for the optional final assistant message'}}
WARNING:utils.ai_wrapper:Attempt 2 failed: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.0: all messages must have non-empty content except for the optional final assistant message'}}
ERROR:utils.ai_wrapper:Final attempt failed after 3 retries. Error: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.0: all messages must have non-empty content except for the optional final assistant message'}}
Start
Import 1
Import 2
Current working directory: /home/id/folder
So
- I am getting errors prior to the very first line of code (print)
- Errors and warnings are for utils.ai_wrapper, which is not yet imported
- The code ends up failing at the end.
When I am running the same command from the console, it works fine.
Can someone please help me to understand what is going on? I spent 3 days with not much progress. One thing I learned though is that the scheduler runs my script as
python /bin/run_scheduled_task.py 'python3.10 myscript.py'
But that command also works alright. I am puzzled. I would appreciate any help!