qq_39993240
qq_39993240
2018-06-02 13:47
采纳率: 33.3%
浏览 938

python监听器的问题,求大神指教

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)

求大神指教

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • oyljerry
    oyljerry 2018-06-02 13:54
    已采纳

    data中有ASCII编码的字符。先编码处理一下

    点赞 评论
  • qq_33355309
    赵青枫 2018-06-02 14:18

    data中有ASCII编码的字符。先编码处理一下

    点赞 评论
  • mlsspp
    mlsspp 2018-06-02 14:45

    data中有ASCII编码的字符。先编码处理一下

    点赞 评论

相关推荐