在Python中,BaseHTTPRequestHandler异常是';我受不了
我使用BaseHTTPServer和BaseHTTPRequestHandler编写了一个小http服务器,现在一切都很好,除了在do_GET()方法中我无法处理以下错误外:在Python中,BaseHTTPRequestHandler异常是';我受不了,python,exception-handling,basehttpserver,basehttprequesthandler,Python,Exception Handling,Basehttpserver,Basehttprequesthandler,我使用BaseHTTPServer和BaseHTTPRequestHandler编写了一个小http服务器,现在一切都很好,除了在do_GET()方法中我无法处理以下错误外: error ! ---------------------------------------- Exception happened during processing of request from ('10.255.255.203', 17055) Traceback (most recent call last):
error !
----------------------------------------
Exception happened during processing of request from ('10.255.255.203', 17055)
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 653, in __init__
self.finish()
File "C:\Python27\lib\SocketServer.py", line 712, in finish
self.wfile.close()
File "C:\Python27\lib\socket.py", line 279, in close
self.flush()
File "C:\Python27\lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10054] An existing connection was forcibly closed by the remote ho
st
----------------------------------------
我知道这是一个错误号为10054的socket.error异常,但是当我用try-except包围有问题的块时,这个异常并没有像我所希望的那样被排除
有什么帮助吗
编辑:添加了一些代码块
def do_GET(self):
try:
self.send_response(200)
self.end_headers()
self.wfile.write("Hello!")
return
except Exception as e:
print "error !"
当一个客户端断开连接时,我得到上面的异常…您能提供一个代码片段吗?具体地说,在代码区,您添加了try-except块,但该块没有按预期工作。我添加了一些代码,有什么帮助吗?有人能帮我解决这个问题吗?您能给我们一个脚本的“迷你”版本,以便我自己测试它吗?看起来例外情况不是来自do_GET部分