【问题标题】:instance has no attribute 'sock'实例没有属性“袜子”
【发布时间】:2014-03-14 12:41:45
【问题描述】:

我有一个使用 Twisted 在 Python 中运行的基本服务器程序。我试图拒绝用户并尝试使用self.sock.close()。当该行被调用时,我得到一个异常:

AttributeError: IphoneChat 实例没有属性“sock”。

这很奇怪,因为在这行代码执行之前并没有导致异常:

from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
class IphoneChat(protocol):
   def connectionMade(self):
      self.sock.close()
      return

就是现在我在尝试拒绝传入连接时更改了它。

【问题讨论】:

  • 在制作任何 cmets 之前,我们需要实际查看一些代码。

标签: python twisted


【解决方案1】:

self.transport.loseConnection() 是使用 twisted 时执行 self.sock.close() 的另一种方式。我不知道为什么它在工作然后停止工作。

【讨论】:

    猜你喜欢
    • 2016-06-29
    • 2012-10-07
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 2014-04-05
    • 2014-11-25
    相关资源
    最近更新 更多