I am seeing an issue with a locally hosted python mock-server. This server takes in byte data and sends them out to a Fluttter mobile application which downloads the data. It is meant to simulate a real server and can be used with a wide variety of data. The following error is seen from the terminal as it attempts to send data:
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)
This is the code block that throws the error
if str(self.path).endswith('/0'):
print('Returning entire Map Data')
payload = self._get_payload(self.db_addr, 'rb')
self.wfile.write(payload)
and this is the function called in the code block above
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
The errors seem to only occur with two of the endpoints. The others seem to send the data just fine. On the Flutter side, the mobile application just recieves a response code of 200, but with no data when this error occurs.
I tried the following solutions with no success:
Python/sockets/ssl EOF occurred in violation of protocol
https://github.com/boto/boto3/issues/3359
python ssl eof occurred in violation of protocol, wantwriteerror, zeroreturnerror
I also tried changing buffer rates to see if slowing the transfer speeds down would have any impact. My thought process here was that since the two endpoints that are failing are the transferring the most amount of data, slowing it down might help it send successfully.
Lastly, I also tried removing the certificate verification thinking that somehow might be blocking the mock-server from sending data.