title: Python if else within a try and except
body: <p>I have the following python code that works well:</p>
  
  <pre><code>try:
      with urlopen("http://my.domain.com/get.php?id=" + id) as response:
          print("Has content" if response.read(1) else "Empty - no content")
  except:
      print("URL Error has occurred")
  </code></pre>
  
  <p>But I am trying to change the if else statement within the try to something like this: so that I can run extra code rather than just print a message</p>
  
  <pre><code>try:
      with urlopen("http://my.domain.com/get.php?id=" + id) as response:
          if response.read(1):
              print("Has content")
          else:
              print("Empty - no content")
  except:
      print("URL Error has occurred")
  </code></pre>
  
  <p>But the above is not working, giving an error related to indent</p>
  
  <p>Any ideas what's wrong?</p>