shougaogao2011 2014-12-05 12:19 采纳率: 0%
浏览 2153

求助!!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 2014-12-05 12: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()

    代码

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败