1. Home
  2. Computing & Technology
  3. Python

Part 4: Handling Errors the Way You Want

From , former About.com Guide

3 of 7

Blackboxing the Error: HTML and PHP

Whichever of PHP or CGI you used earlier in the tutorial, that is what you should troubleshoot next. We do this in a terminal shell, not in the web browser. For PHP, you will use the interpreter 'php5-cgi'. Naturally, CGI can be executed with the Python interpreter, but remember to hardwire the feed option into the program. Whichever you use, the terminal output should include feedback from the Python interpreter that reads similar to this:

Traceback (most recent call last):
File "./RSSReader.py", line 92, in ?
main()
File "./RSSReader.py", line 87, in main
output = formBody(feedname)
File "./RSSReader.py", line 82, in formBody
feedurl = feed.feeddata(feedname)
File "./RSSReader.py", line 53, in feeddata
feedaddress = feedinfo[feedname]
KeyError: ''
In the PHP version of the program this error message appears before any HTML output. Because there is HTML output eventually, we know that the PHP program is not the cause of the present problem.

If you have read my tutorial on Python's exceptions, errors, and warnings, you know what KeyError means. If not, you will want to read that before going on from here. The next few pages will not make much sense otherwise.

Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.