title: Indentation error on try, except, else block in python
body: <p>Further to a question I asked <a href="https://stackoverflow.com/questions/16559077/opening-text-files-from-a-list-within-another-text-file-using-python">here</a>, I'm stuck sorting out an error exception.
  I have sorted out reading a list of files from another file, but I'm struggling with if one of the files referenced doesn't exist.
  I want to be able to identify the error, email out and then create the file for later use.
  However, I'm getting an indentation error for the &quot;try, except, else&quot; block I'm putting in.
  It looks like it should work but I just can't get it to run!
  Gah!  Help!!!</p>
  <p>The log text file contains the following:</p>
  <p>//server-1/data/instances/devapp/log/audit.log</p>
  <p>//server-1/data/instances/devapp/log/bizman.db.log</p>
  <p>//server-1/data/instances/devapp/log/foo.txt     <em>#  This file doesn't exist on the server</em></p>
  <p>My code is as follows.  I thought it best to post it in entirety rather than a snippet, in case it's something earlier in the program that's knackering it!</p>
  <pre><code>import os, datetime, smtplib
  today = datetime.datetime.now().strftime('%Y-%m-%d')
  time_a = datetime.datetime.now().strftime('%Y%m%d %H-%M-%S')
  checkdir = '/cygdrive/c/bob/python_'+ datetime.datetime.now().strftime('%Y-%m-%d')+'_test'
  logdir = '/cygdrive/c/bob/logs.txt'
  errors = '/cygdrive/c/bob/errors.txt'
  
  #email stuff
  sender = 'errors@company.com'
  receivers = 'bob@company.com'
  message_1 = &quot;&quot;&quot;From: errors &lt;errors@company.com&gt;
  To: Bob &lt;bob@company.com&gt;
  Subject: Log file not found on server
  
  A log file has not been found for the automated check. 
  The file has now been created.
  &quot;&quot;&quot; 
  #end of email stuff
  
  
  try:
                  os.chdir (checkdir) # Try opening the recording log directory    
  except (OSError, IOError), e: # If it fails then :
                  os.mkdir (checkdir)  #  Make the new directory
                  os.chdir (checkdir)  #  Change to the new directory
                  log = open ('test_log.txt', 'a+w') #Create and open log file
  else :
                  log = open ('test_log.txt', 'a+w') #Open log file
  
  log.write (&quot;***starting file check at %s  ***\r\n\r\n&quot;%tme_a)
  
  def log_opener (logdir) :
      with open(logdir) as log_lines:  #open the file with the log paths in
          for line in log_lines:  # for each log path do :
              timestamp = time_a + ('  Checking ') + line + ( '\r\n' )
              try:
                  with open(line.strip()) as logs:
              except (OSError,IOError), e:
                  try:
                  smtpObj = smtplib.SMTP('localhost')
                  smtpObj.sendmail(sender, receivers, message)         
                  log.write (timestamp)
                  log.write (&quot;Log file not found.  Email sent.  New file created.&quot;)
              except SMTPException:
                  log.write (timestamp)
                  log.write (&quot;Log file not found.  Unable to send email.  New file created.&quot;)
              
          else :  #  The following is just to see if there is any output...  More stuff to be added here!
              
              print line + ( '\r\n' )
              log.write (timestamp)
              print &quot;&quot;.join(logs.readlines())
              
  print log_opener(logdir)
  </code></pre>
  <p>The error I'm getting is as follows:</p>
  <pre><code>$ python log_5.py
    File &quot;log_5.py&quot;, line 38
      except (OSError,IOError), e:
      ^
  IndentationError: expected an indented block
  </code></pre>
  <p>As far as I can tell, it should work but...</p>
  <p>As an additional note, I've not been learning long, so a lot of my code is modified from various tutorials or borrowed from here, or elsewhere on the web.
  I'm probably making a very basic mistake here, so bear with me if I am!</p>
  <p>Many thanks for your help!</p>