title: LaunchD Job Failed weird reason: 2
body: <p>I've been trying to use launchD to execute a script every 24 hours, but I keep receiving an error for weird reason: 2; I understand that this means that the file was not found, but I checked and double checked to ensure that the filepath in the Program Argument is correct. The script runs fine when I execute it in the terminal. Any ideas on why this won't work? </p>
  
  <p>The script simply scrapes information of newly added startups off of AngelList and sends it out via e-mail. </p>
  
  <p>Below is my launchD and Python script:</p>
  
  <pre><code>Python: 
  
  #!/opt/local/bin/python2.6
  import urllib
  import json
  import datetime
  import ast
  import time
  import smtplib
  from pymongo import MongoClient
  from email.mime.multipart import MIMEMultipart
  from email.mime.text import MIMEText
  
  ... #code omitted 
  
  def find_data(): 
     client = MongoClient()
     client = MongoClient('localhost', 27017)
     db = client.tiger_labs
     collection = db.new_startups
     existing_names = []
     for startup in collection.find(): 
        existing_names.append(startup.get('name')) # inserts all "already-found" startups to the database
  
     market_tags = ["mobile health", "health care", "health care information technology", "health and wellness", "personal health"] # lists out all tags
  
     ... # code omitted
  
     text += "&lt;/html&gt;"
     if text != "&lt;html&gt;&lt;/html&gt;": # sends e-mail if not empty
         nathan = "testerisgood@gmail.com"
         tigerlabs = "****@tigerlabs.co, *****@tigerlabs.co"
         msg = MIMEMultipart('alternative')
         msg['Subject'] = "New Startups"
         msg['From'] = nathan
         msg['To'] = tigerlabs
         part1 = MIMEText(text, 'html')
         msg.attach(part1)
         server = smtplib.SMTP('smtp.gmail.com:587')  
         server.starttls()  
         server.login("testerisgood@gmail.com", "******")
         server.sendmail(nathan, tigerlabs, msg.as_string())
         server.quit()
         print "sent"
     else: # purely for testing reasons; wanted to see if launchD was executing
         server = smtplib.SMTP('smtp.gmail.com:587')  
         server.starttls()  
         server.login("testerisgood@gmail.com", "*********")
         server.sendmail("testerisgood@gmail.com", "*****@princeton.edu", "Hi it worked.")
         server.quit()
         print "not_sent"
  
  find_data()
  
  LaunchD:
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;dict&gt;
      &lt;key&gt;Label&lt;/key&gt;
      &lt;string&gt;com.tigerlabs.TigerLabs&lt;/string&gt;
      &lt;key&gt;ProgramArguments&lt;/key&gt;
      &lt;array&gt;
          &lt;string&gt;/Users/nathanlam/Desktop/Programming_Labs/Coding/TigerLabs.py&lt;/string&gt;
      &lt;/array&gt;
      &lt;key&gt;StartInterval&lt;/key&gt;
      &lt;integer&gt;86400&lt;/integer&gt;
      &lt;key&gt;KeepAlive&lt;/key&gt;
      &lt;dict&gt;
            &lt;key&gt;NetworkState&lt;/key&gt;
            &lt;true /&gt;
      &lt;/dict&gt;
      &lt;key&gt;StandardErrorPath&lt;/key&gt;
      &lt;string&gt;/tmp/test.stderr&lt;/string&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>