[Twisted-Python] factory class has no __class__ attribute!
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) File "c:\apps\python\244\lib\site-packages\twisted\internet\posixbase.py", line 467, in listenTCP p.startListening() 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__, self._realPortNumber)) 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. Regards, 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(s.pages[s.path]) else: s.setResponseCode(http.NOT_FOUND) s.write("<h1>Not Found!</h1>Sorry, no such page.") s.finish() 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) reactor.run()
On Thu, 01 Mar 2007 15:37:41 +0000, John Pote <johnpote@jptechnical.co.uk> wrote:
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:
[snip] AttributeError: class myhttpFactory has no attribute '__class__'
anyone shed any light on this?
[snip]
class myhttpFactory(http.HTTPFactory): protocol = httpProtocol
Here you defined a protocol factory class.
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)
Here you passed it to listenTCP, when you should have pass an instance of it to listenTCP: reactor.listenTCP(8000, myhttpFactory())
reactor.run()
Jean-Paul
Hi John, On Thu, 01 Mar 2007 09:37:41 -0600, John Pote <johnpote@jptechnical.co.uk> wrote: [SNIP]
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(s.pages[s.path]) else: s.setResponseCode(http.NOT_FOUND) s.write("<h1>Not Found!</h1>Sorry, no such page.") s.finish()
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) ^^^^^^^^^^^^^ You have to pass an *instance* of myhttpFactory, not the class itself.
Hope this helps, L. Daniel Burr
Thanks Jean-Paul and Daniel. Had to be a trivial problem. My excuse is I typed it in at the tail end of a migraine and I'm struggleing with my vari-focals anyway. Just didn't see the () to make an instance of the factory. Thanks boys. John L. Daniel Burr wrote:
^^^^^^^^^^^^^ You have to pass an *instance* of myhttpFactory, not the class itself.
Hope this helps,
L. Daniel Burr
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Jean-Paul Calderone
-
John Pote
-
L. Daniel Burr