[Twisted-web] Twisted Network Programming Essentials

Tommi Virtanen tv at twistedmatrix.com
Mon Nov 21 23:57:11 MST 2005

On Tue, 2005-11-22 at 00:59 +0000, Stephen Nightingale wrote:
> Fine Book.  I'm working through the examples.
> Hit a problem with the wordcountproxy.py example,
> under the explanation of HTTP Proxy Servers, on page 62..
> As this __might__ be an issue with Twisted itself,
> I'm cross-posting here as well as back to O'Reilly errata.
> The issue is that the:
> 'reactor.listenTCP(WEB_PORT, WebReportFactory(counter))'
> call precipitates an error message in  _getfullpathname in
> Lib/ntpath.py, called from web/http.py, and the error is:
> 'TypeError: coercing to Unicode: need string or buffer, WordCounter
> found'
> I wonder if anyone else has come across this issue?
> Any insights gratefully received,

Did you type it in yourself? It seems like the wordCounter
argument to WebReportFactory.__init__ is getting to
HTTPFactory.__init__, which seems to think it is logPath.
But the book I have in front of me seems to be correct:

class WebReportFactory(http.HTTPFactory):
    def __init__(self, wordCounter):
        self.wordCounter = wordCounter
    counter = WordCounter()
    reactor.listenTCP(WEB_PORT, WebReportFactory(counter))

More information about the Twisted-web mailing list