2 shougaogao2011 shougaogao2011 于 2014.12.05 20:19 提问

求助!!python web AttributeError 怎么改?

import socket
import xml.dom.minidom
import web
import threading
import json,time

g_nodetemp =''
global a
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello():
def GET(self,name):
name = (open('client.txt','r')).read().rstrip()
datatime = time.asctime()
print 'hello => '
print 'datatime',datatime
return name

class Tcpclient():
'''docstring for Tcpclient'''

def __init__(self):
    self.host ='192.168.48.78'
    self.port = 9005
    self.temp = ''
def Start(self):
    s = socket.socket()
    s.connect((self.host,self.port))
    print 'Connection Succeful'
    a = True
    print a
    while True:
        try :
            datarecv = s.recv(1024).rstrip()
            self.temp = self.temp + datarecv
            indexTail = self.temp.find('</MotePacket>')
            indexHead = self.temp.find('<MotePacket>')
            if indexHead > 0 and indexTail>0 and indexHead < indexTail:
                datarecv = self.temp[indexHead: indexTail+13]
                get_tagname(datarecv)
                self.temp = self.temp[indexTail+13:]
        except Exception,e:
            print 'connecting fail!',e
            a = False

def interval():
if a == True:
time.sleep(10)
else:
test()

def get_tagname(tagname):
global g_nodetemp

dom = xml.dom.minidom.parseString(tagname)
root = dom.documentElement
for node in root.getElementsByTagName("PacketName"):
for child in node.childNodes:
print node.tagName+':',child.nodeValue
Dicdata = {}
Dicdata[node.tagName] = child.nodeValue
print Dicdata
for node in root.getElementsByTagName("NodeId"):
for child in node.childNodes:
print node.tagName+':',child.nodeValue
Dicdata[node.tagName] = child.nodeValue
print Dicdata
datatime = time.asctime()
Dicdata['time'] = datatime
print 'datatime',datatime
datajson = json.dumps(Dicdata)
print 'datajson',datajson
f = open('client.txt','a')
f.write(datajson)
f.close()
def test():
m = Tcpclient()
m.Start()

if name == '__main__':
print 'start client =>'
threading.Thread(target=test).start()
print 'start web server =>'
threading.Thread(target= app.run).start()
print 'interval=>'
threading.Thread(target=interval).start()
返回错误AttributeError:'module'object has no attribute'application'

2个回答

shougaogao2011
shougaogao2011   2014.12.05 20:24

import socket
import xml.dom.minidom
import web
import threading
import json,time

g_nodetemp =''
global a
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello():
def GET(self,name):
name = (open('client.txt','r')).read().rstrip()
datatime = time.asctime()
print 'hello => '
print 'datatime',datatime
return name

class Tcpclient():
'''docstring for Tcpclient'''

def __init__(self):
    self.host ='192.168.48.78'
    self.port = 9005
    self.temp = ''
def Start(self):
    s = socket.socket()
    s.connect((self.host,self.port))
    print 'Connection Succeful'
    a = True
    print a
    while True:
        try :
            datarecv = s.recv(1024).rstrip()
            self.temp = self.temp + datarecv
            indexTail = self.temp.find('</MotePacket>')
            indexHead = self.temp.find('<MotePacket>')
            if indexHead > 0 and indexTail>0 and indexHead < indexTail:
                datarecv = self.temp[indexHead: indexTail+13]
                get_tagname(datarecv)
                self.temp = self.temp[indexTail+13:]
        except Exception,e:
            print 'connecting fail!',e
            a = False

def interval():
if a == True:
time.sleep(10)
else:
test()

def get_tagname(tagname):
global g_nodetemp

dom = xml.dom.minidom.parseString(tagname)
root = dom.documentElement
for node in root.getElementsByTagName("PacketName"):
for child in node.childNodes:
print node.tagName+':',child.nodeValue
Dicdata = {}
Dicdata[node.tagName] = child.nodeValue
print Dicdata
for node in root.getElementsByTagName("NodeId"):
for child in node.childNodes:
print node.tagName+':',child.nodeValue
Dicdata[node.tagName] = child.nodeValue
print Dicdata
datatime = time.asctime()
Dicdata['time'] = datatime
print 'datatime',datatime
datajson = json.dumps(Dicdata)
print 'datajson',datajson
f = open('client.txt','a')
f.write(datajson)
f.close()
def test():
m = Tcpclient()
m.Start()

if name == '__main__':
print 'start client =>'
threading.Thread(target=test).start()
print 'start web server =>'
threading.Thread(target= app.run).start()
print 'interval=>'
threading.Thread(target=interval).start()

代码

oyljerry
oyljerry   Ds   Rxr 2015.01.01 18:59

module'object has no attribute'application'

没有对应属性

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!