Why won't this APScheduler code work?
<p>been looking for quite a while for an answer so I turned to here! It gives me the error, "Invalid Index" for the sched.start()!</p>

<pre><code>import random
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
import smtplib
import email


def randEmail():
    #Gets randLine
    file_object = open("lyrics.txt", "r")
    randLine = random.randint(1, 10)
    for i, line in enumerate(file_object):
        if i == randLine:
            break
    #line = randomly generated line
    file_object.close()

    #Email
    emails = [ 'emails']


    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login('login', 'password')
    server.sendmail('login',emails, line)
    server.quit()

    #Prints to notepad saying completed
    Date = datetime.datetime.now()


    with open("Server_Quit.txt", "r+") as ServerQuit:
        ServerQuit.write("Server has quit at " + str(Date))
    ServerQuit.close()


#Unsure whether working
#sched.Scheduler()
#sched.start()
#sched.add_interval_job(randEmail, hours=24, start_date='2016-10-10 18:30')

sched = BlockingScheduler()
@sched.randEmail('cron', day_of_week='mon-fri', hour=18, minutes=30)
sched.start()
</code></pre>

<p>I appreciate any help! I've tried my best to get this working on my own and have ironed through all the other problems myself, but can't get this working. Also, if I want this to run on my PC and do this everyday, can I just add it to startup processes, and when I start my PC the scheduler will start? </p>

<p>You can add a job to a scheduler by decorating a function with the <code>scheduled_job</code> decorator:</p>

<pre><code>from apscheduler.schedulers.blocking import BlockingScheduler

sched = BlockingScheduler()

# minute=30 not minutes=30
@sched.scheduled_job('cron', day_of_week='mon-fri', hour=18, minute=30)
def randEmail():
    #Gets randLine
    with open("lyrics.txt", "r") as file_object:
        randLine = random.randint(1, 10)
        for i, line in enumerate(file_object):
            if i == randLine:
                break
    #line = randomly generated line

    #Email
    emails = [ 'emails']

    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login('login', 'password')
    server.sendmail('login', emails, line)
    server.quit()

    #Prints to notepad saying completed
    Date = datetime.datetime.now()

    # You don't have to close the file if you use the with statement
    with open("Server_Quit.txt", "r+") as ServerQuit:
        ServerQuit.write("Server has quit at " + str(Date))

sched.start()
</code></pre>

<p>You can also use the <code>add_job</code> method:</p>

<pre><code>sched.add_job(randEmail, 'cron', day_of_week='mon-fri', hour=18, minute=30)
sched.start()
</code></pre>

<p>I can't see any reason why it would not work as a startup process.</p>

python apscheduler