好吧,我一直在写一个代理来接收httpget请求并将它们转换成httppost请求(因为很多python媒体播放器只支持GET)。所以我知道我在缓存这些结果,我只下载了一次url,我把很多代码从super类移到了sub类,并对其进行了更改,这样我就可以将相同的内容发送到多个服务器连接(例如,如果建立了服务器连接,我只会将其附加到下载实例(如果可用的话)。在
不管怎样,除了最后一部分(由于某些原因,在我调用loseConnection之前,http通道被设置为None(这没有任何错误,比如internet出站等),这会导致一个错误:None对象没有我调用loseConnection的属性transport。在
这是密码
self.connectionDone = True
print self.producers
for p in self.producers:
print p
print p.channel
print dir(p)
p.channel.transport.loseConnection()
self.transport.loseConnection()
以及自我频道设置为none(每个setattr调用上的回溯模块的print_堆栈)
注意:看最后几行,我想这就是问题所在。在
^{pr2}$这是我得到的none属性异常
Traceback (most recent call last):
File "C:\Program Files\Python 2.6.2\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7303, in MainLoop
return _core_.PyApp_MainLoop(*args, **kwargs)
File "C:\Program Files\Python 2.6.2\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14640, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\internet\_threadedselect.py", line 243, in _interleave
getattr(self, '_process_' + msg)(*args)
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\internet\_threadedselect.py", line 209, in _process_Notify
_logrun(selectable, _drdw, selectable, method, dct)
--- <exception caught here> ---
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\python\log.py", line 84, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\python\log.py", line 69, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\python\context.py", line 59, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\python\context.py", line 37, in callWithContext
return func(*args,**kw)
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\internet\_threadedselect.py", line 303, in _doReadOrWrite
self._disconnectSelectable(selectable, why, method == "doRead")
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\internet\posixbase.py", line 253, in _disconnectSelectable
selectable.connectionLost(f)
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\internet\tcp.py", line 677, in connectionLost
Connection.connectionLost(self, reason)
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\internet\tcp.py", line 519, in connectionLost
protocol.connectionLost(reason)
File "C:\Program Files\Python 2.6.2\lib\site-packages\twisted\web\http.py", line 489, in connectionLost
self.handleResponseEnd()
File "C:\Documents and Settings\Admin\My Documents\Mercurial\sharky\ProxyServer.py", line 103, in handleResponseEnd
p.channel.transport.loseConnection()
exceptions.AttributeError: 'NoneType' object has no attribute 'transport'
如果没有互联网,连接可能会丢失。只需要连接的一端调用shutdown()或close()。你排除了吗?即使你有,为了代码是正确的,它仍然需要处理这种可能性,因为它可能会在其他时间发生。看到了吗请求.notifyFinish. 在
相关问题 更多 >
编程相关推荐