python监听器收到客户端的请求后,主动do_Post给客户端发一条请求,收到客户端的应答之后通过原请求给客户端返回去,怎么操作,哪位大神给知道一下
给原请求应答的代码
if not self.wfile.closed:
self.send_response(200)
if not self.wfile.closed:
print (strs)
self.send_header("Content-Length", str(len(strs)))
self.end_headers()
self.wfile.write(strs)
strs内容如下
<html><head></head><body><table style="border-collapse:collapse"><tr><td style="width:200px;border: 1px #000 solid;word-break:keep-all">出参:</td><td style="border: 1px #000 solid;word-break:keep-all">{RTN_CODE=0, RTN_MSG=BP节点号:[311],业务程序运行正常}</td></tr><tr><td style="border: 1px #000 solid;word-break:keep-all" colspan="2">网页签约异步处理结果如下:</td></tr><tr><td colspan="2"><table style="border-collapse:collapse"><tr><td style="border: 1px #000 solid;word-break:keep-all">第二结果集</td><td style="border: 1px #000 solid;word-break:keep-all">OCCUR_DATE</td><td style="border: 1px #000 solid;word-break:keep-all">TRD_BIZ_STATUS</td><td style="border: 1px #000 solid;word-break:keep-all">PY_ORG_CODE</td><td style="border: 1px #000 solid;word-break:keep-all">OCCUR_TIME</td><td style="border: 1px #000 solid;word-break:keep-all">SERIAL_NO</td><td style="border: 1px #000 solid;word-break:keep-all">PY_ACC</td></tr><tr><td style="border: 1px #000 solid;word-break:keep-all">1</td><td style="border: 1px #000 solid;word-break:keep-all">20180602</td><td style="border: 1px #000 solid;word-break:keep-all">9</td><td style="border: 1px #000 solid;word-break:keep-all">7</td><td style="border: 1px #000 solid;word-break:keep-all">20454058</td><td style="border: 1px #000 solid;word-break:keep-all">201806020000000033</td><td style="border: 1px #000 solid;word-break:keep-all"></td></tr></table></td></tr></table></body>
报错如下
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 18521)
Traceback (most recent call last):
File "D:\Install\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "D:\Install\Python27\lib\SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "D:\Install\Python27\lib\SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "D:\Install\Python27\lib\SocketServer.py", line 639, in __init__
self.handle()
File "D:\Install\Python27\lib\BaseHTTPServer.py", line 343, in handle
self.handle_one_request()
File "D:\Install\Python27\lib\BaseHTTPServer.py", line 331, in handle_one_request
method()
File "D:\javaProject\hftx\httpserver2_hftx.py", line 47, in do_POST
self.wfile.write(strs)
File "D:\Install\Python27\lib\socket.py", line 316, in write
data = str(data) # XXX Should really reject non-string non-buffers
UnicodeEncodeError: 'ascii' codec can't encode characters in position 136-137: ordinal not in range(128)