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

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 2018-06-02 13:54
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构