求指正!!!!web 传输数据 发生错误 IOError: [Errno 22] Invalid argument

shougaogao2011 2014-11-27 04:25:54
Traceback (most recent call last):
File "C:\Python27\lib\web\wsgiserver\__init__.py", line 1245, in communicate
req.respond()
File "C:\Python27\lib\web\wsgiserver\__init__.py", line 775, in respond
self.server.gateway(self).respond()
File "C:\Python27\lib\web\wsgiserver\__init__.py", line 2018, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "C:\Python27\lib\web\httpserver.py", line 306, in __call__
return self.app(environ, xstart_response)
File "C:\Python27\lib\web\httpserver.py", line 274, in __call__
return self.app(environ, start_response)
File "C:\Python27\lib\web\application.py", line 279, in wsgi
result = self.handle_with_processors()
File "C:\Python27\lib\web\application.py", line 249, in handle_with_processors
return process(self.processors)
File "C:\Python27\lib\web\application.py", line 245, in process
print >> web.debug, traceback.format_exc()
File "C:\Python27\lib\web\webapi.py", line 479, in _debugwrite
out.write(x)
IOError: [Errno 22] Invalid argument
代码:
import socket
import xml.dom.minidom
import web
import threading
import json
import time
g_nodetemp =''

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


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

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

def __init__(self):
self.host ='192.168.48.125'
self.port = 9005
#self.count = 1
self.temp = ''
#print 'init Tcpclient...'
def Start(self):
#print 'try start client...'
s = socket.socket()
s.connect((self.host,self.port))
print 'Connection Succeful'
while True:
datarecv = s.recv(1024).rstrip()
#print 'data =>',datarecv
self.temp = self.temp + datarecv
#print self.temp
indexTail = self.temp.find('</MotePacket>')
#print 'indexTail=',indexTail
indexHead = self.temp.find('<MotePacket>')
#print 'Head ',indexHead
if indexHead > 0 and indexTail>0 and indexHead < indexTail:
datarecv = self.temp[indexHead: indexTail+13]
#print 'datarecv=>',datarecv
get_tagname(datarecv)

#self.count += 1
#print datarecv
self.temp = self.temp[indexTail+13:]

#s.close()

def get_tagname(tagname):
global g_nodetemp
dom = xml.dom.minidom.parseString(tagname)
# print dom
root = dom.documentElement
for node in root.getElementsByTagName("PacketName"):
for child in node.childNodes:
print "'"+node.tagName+"'"+':',"'"+child.nodeValue+"'"
#print 'g_nodetemp=>'
# global g_nodetemp
g_nodetemp = g_nodetemp + node.tagName + ':'+child.nodeValue
#print 'get_tagname ',g_nodetemp
#g = getInfo()
#print 'get_tagname try test getInfo => ',g
for node in root.getElementsByTagName("NodeId"):
for child in node.childNodes:
print "'"+ node.tagName+"'"+':',child.nodeValue
# global g_nodetemp
g_nodetemp = g_nodetemp + node.tagName + ':' + child.nodeValue
# print 'g_nodetemp=>',g_nodetemp
f = open('client.txt','w')
f.write(g_nodetemp)
f.close()

def test():
# thread.start_new_thread(app.run())
m = Tcpclient()
m.Start()
# app.run()
#m.Start()

if __name__ == '__main__':
print 'start client =>'
threading.Thread(target=test).start()
print 'start web server =>'
# app.run()
threading.Thread(target= app.run).start()
求指正错误
...全文
488 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ehes73 2014-11-27
  • 打赏
  • 举报
回复
先把代码贴成python格式吧,这样没法看!

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧