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 帮我调试idea基于spring boot项目
  • ¥15 es 7.17.20版本生成时间戳
  • ¥15 wpf dategrid表头排序图标自定义
  • ¥15 分析下图所示同步时序逻辑电路的逻辑功能。
  • ¥15 halcon联合c#遇到了问题不能解决
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合