Twisted + exceptions.AttributeError:'datetime.timedelta'对象没有属性'time'

时间:2013-03-04 01:49:58

标签: python twisted

我编写了Twisted Server和常规套接字客户端(因为客户端没有安装Twisted)。服务器代码的一部分如下

import time
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor

class Server:
    def method(self, addr,port,sock):
        command = 'tcpdump -i any  \'src ' +str(addr) +' and port 80\' -w '+str(addr)+ '_download_' +str(time.time())+'.txt &'
        os.system(command)
        sock.transport.write('ok')


class Echo(Protocol):
    def dataReceived(self,data):
        s = Server()
        #extract client ip from the method self.transport.getPeer()
        #extract client port from the data received 
        print data
        s.method(client_ip, port, self)#the client ip and port are extracted from the request received

def main():
    f = Factory()
    f.protocol = Echo
    reactor.listenTCP(33456, f)
    reactor.run()

if __name__ == '__main__':
    main()

此方法适用于第一个客户端请求但在第二个请求时失败并出现以下错误

exceptions.AttributeError: 'datetime.timedelta' object has no attribute 'time'以及命令的行号(我使用time.time()方法获取文件名)

任何人都可以指出我正确的方向我做错了吗?或者为什么会抛出错误?

编辑:

我还没有在这里发布完整的代码,但回溯是

Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 586, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 199, in doRead
    rval = self.protocol.dataReceived(data)
  File "dc.py", line 191, in dataReceived
    dc.multiQ(client_ip,multiq_port,self)
  File "dc.py", line 73, in multiQ
    command = 'tcpdump -i any  \'src ' +str(addr) +' and port 80\' -w '+str(addr)+ '_download_' +str(time.time())+'.txt &'#change any to eth0
exceptions.AttributeError: 'datetime.timedelta' object has no attribute 'time'

0 个答案:

没有答案