[Twisted-Python] factory class has no __class__ attribute!

John Pote johnpote at jptechnical.co.uk
Thu Mar 1 10:37:41 EST 2007

Hi everyone,
Justed started out to get a twisted http server going. typed in example 
4.2 from Fettig's book but when I run it this strange error is reported:

twisted ver:2.5.0
python ver:2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
Traceback (most recent call last):
  File "dataServe.py", line 31, in ?
    reactor.listenTCP(8000, myhttpFactory)
line 467, in listenTCP
  File "c:\apps\python\244\lib\site-packages\twisted\internet\tcp.py", 
line 739, in startListening
    log.msg("%s starting on %s" % (self.factory.__class__, 
AttributeError: class myhttpFactory has no attribute '__class__'

anyone shed any light on this?

Also, for your information, I tried Fettig's example 2.6 
'dataforward.py'. This works fine on my Linux box but just hangs on my 
win XP box.

using Py 2.4.4 and Twisted 2.5.0 on winXP and Centos4.4 Linux.

John Pote

source code
import sys
from twisted.web import http

class httpRequests(http.Request):
    pages = {
        '/':    '<h1>Home</h1>Home page',
        '/test':'<h1>Test</h1>Test page',
    def process(s):
        if s.pages.has_key(s.path):
            s.write("<h1>Not Found!</h1>Sorry, no such page.")

class httpProtocol(http.HTTPChannel):
    requestFactory = httpRequests

class myhttpFactory(http.HTTPFactory):
    protocol = httpProtocol

if __name__ == "__main__":
    from twisted.internet import reactor
    from twisted._version import version
    print "twisted ver:"+version.short()
    print "python ver:"+sys.version

    reactor.listenTCP(8000, myhttpFactory)

More information about the Twisted-Python mailing list