[Twisted-Python] Webcat.py script from the O'Reilly Twisted book doesn't work on my system. Why?

Jonathan Mark jonathansamuel at yahoo.com
Mon Feb 19 20:54:32 EST 2007


The following code, from the O'Reilly Twisted book, is
supposed to download and print out the contents of a
URL. When I run it, however, the value of data is
empty.

If I type in a bad URL it gives me an error, as it is
supposed to. If I replace 'print data' with print
"hello world" it prints "hello world." The only thing
that doesn't work is that the value of data is empty. 

I am running Twisted 2.1, Python 2.4.3 and Red Hat 7.3
. What am I doing wrong? Do I need to upgrade to
Twisted 2.5?

#######################################
from twisted.web import client
from twisted.internet import reactor
import sys
def printPage(data):
   print data 
   reactor.stop()

def printError(failure):
   print >> sys.stderr, "Error:",
failure.getErrorMessage()
   reactor.stop()

if len(sys.argv) ==2:
   url = sys.argv[1]
   client.getPage(url).addCallback(
     printPage).addErrback(
     printError)
   reactor.run()
else:
   print "(Usage: webcat.py <URL>"




 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com




More information about the Twisted-Python mailing list