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是一个网页内容,报错如下
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)
求大神指教