我正在嘗試修改Twisted,看看它到底是怎么回事。因此,我買了杰西卡·麥凱拉(Jessica McKellar)和阿貝·費(fèi)蒂格(Abe Fettig)撰寫的第二版《扭曲》,下載并安裝了Python,Twisted和zope.interface,并嘗試輸入并運(yùn)行第12頁上的第一個(gè)示例:from twisted.internet import reactor, protocolclass EchoClient(protocol.Protocol): def connectionMade(self): self.transport.write("Hello, Stupid!") def dataReceived(self, data): print "Server said: ", data self.transport.loseConnection()class EchoFactory(protocol.ClientFactory): def BuildProtocol(self, addr): return EchoClient() def clientConnectionFailed(self, connector, reason): print "Connection Failed." reactor.stop() def clientConnectionLost(self, connector, reason): print "Connection lost." reactor.stop()reactor.connectTCP("localhost", 8000, EchoFactory())reactor.run()也有一個(gè)服務(wù)器部分。我運(yùn)行了服務(wù)器程序,然后在另一個(gè)cmdline窗口中運(yùn)行了客戶端程序(如上)。它產(chǎn)生了:"Unhandled ErrorTraceback.. (several lines - see attached screen-capture (oops - this won't let me attach images!)在callWithContext中的文件“ C:\ Python27 \ lib \ site-package \ twisted \ python \ context.py”第81行---文件“ C:\ Python27 \ lib \ site-packages \ twisted \ internet \ selectreactor.py”,第151行,_doReadOrWrite為什么= getattr(selectable,method)()文件“ C:\ Python27 \ lib \ site-packages \ twisted \ internet \ tcp.py”,第593行,doConnect self._connectDone ().. exceptions.TypeError:'NoneType'對象不可調(diào)用。連接失敗。如果我是Python專家,那么這個(gè)問題可能對我來說更清楚了,但我對此很陌生-來自C#,F(xiàn)#,C ++背景。您認(rèn)為可能是什么原因造成的-其他人遇到了這個(gè)問題嗎?令人沮喪-如果我什至無法獲得第一個(gè)完全平凡的示例來運(yùn)行,我不能說這是一項(xiàng)簡單的技術(shù)!我使用的是Windows 8 x64,Python 2.7.5,Twisted 13.0.0(安裝程序?yàn)門wisted-13.0.0.win-amd64-py2.7.msi),并且我添加了python(C:\ Python27 )和PATH env變量的腳本。
試圖運(yùn)行McKellar&Fettig的Twisted書中的第一個(gè)示例的異常
繁星點(diǎn)點(diǎn)滴滴
2021-03-29 17:07:02