title: Python: raising error for print output of function
body: <p>I am using the <a href="https://github.com/LevPasha/Instagram-API-python/blob/master/InstagramAPI/InstagramAPI.py" rel="nofollow noreferrer">InstagramAPI module from this github</a> to create a script that posts pictures at certain time. A snippet below shows part of the code:</p>
  
  <pre><code>Insta = InstagramAPI(account_name, password)
  Insta.login()
  InstagramAPI.uploadPhoto(post_path, caption)
  InstagramAPI.logout()
  </code></pre>
  
  <p>This works fine, unless the picture is in the wrong format. If it is in the wrong format, nothing is posted and this is printed:</p>
  
  <pre><code>Request return 400 error!
  {u'status': u'fail', u'message': u"Uploaded image isn't in the right format"}
  </code></pre>
  
  <p>I have a function that will re-size if it isn't in the correct format.
  However, it is just print and not an error. Therefor, I can not put this in a try/except. So if the file isn't in the right format, it just skips and posts nothing.</p>
  
  <p>Does anyone know of a way I could have my code save the print output to a variable so I can check if it contains "Uploaded image isn't in the right format" and raise an error if so?</p>