本地Python Mock HTTPS Server遭遇ssl.SSLEOFError问题求助
问题:Python Mock Server SSL传输错误,Flutter端收不到数据
本地搭建了Python mock-server,用于接收字节数据并发送给Flutter移动应用下载,模拟真实服务器,支持多种数据类型。但在两个特定端点发送数据时出现错误,Flutter端收到200响应码但无数据,其他端点传输正常。
错误日志
Exception occurred during processing of request from ('127.0.0.1', 52384) Traceback (most recent call last): File "C:\Python310\lib\socketserver.py", line 316, in _handle_request_noblock self.process_request(request, client_address) File "C:\Python310\lib\socketserver.py", line 347, in process_request self.finish_request(request, client_address) File "C:\Python310\lib\socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) File "D:\git\****\*******\modules\request_handler.py", line 49, in __init__ super().__init__(*args) File "C:\Python310\lib\socketserver.py", line 747, in __init__ self.handle() File "C:\Python310\lib\http\server.py", line 427, in handle self.handle_one_request() File "C:\Python310\lib\http\server.py", line 415, in handle_one_request method() File "D:\git\******\************\modules\request_handler.py", line 246, in do_GET self.wfile.write(payload) File "C:\Python310\lib\socketserver.py", line 826, in write self._sock.sendall(b) File "C:\Python310\lib\ssl.py", line 1236, in sendall v = self.send(byte_view[count:]) File "C:\Python310\lib\ssl.py", line 1205, in send return self._sslobj.write(data) ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2384)
抛出错误的代码块
if str(self.path).endswith('/0'): print('Returning entire Map Data') payload = self._get_payload(self.db_addr, 'rb') self.wfile.write(payload)
调用的_get_payload函数代码
def _get_payload(self, path, mode): payload = '' if os.path.isfile(path): file = open(path, mode=mode) payload = file.read() file.close() elif os.path.isdir(path): #Gets the list of all files in the directory filenames = next(os.walk(path), (None, None, []))[2] length = len(filenames) if length == 0: return payload #Get the index of the file to send fileIndex = 0 if path in Request_Handler.multipleFileCounter: fileIndex = Request_Handler.multipleFileCounter[path] + 1 if fileIndex >= length: fileIndex = 0 #Update stored index, and set payload Request_Handler.multipleFileCounter.update({path: fileIndex}) file = open(path + "\\" + filenames[fileIndex], mode=mode) payload = file.read() file.close() return payload
已尝试的解决方案
- 参考Stack Overflow及GitHub相关问题方案
- 调整缓冲速率降低传输速度
- 移除证书验证
内容的提问来源于stack exchange,提问作者StealthyShadow
相关产品推荐
相关产品推荐

