# Buggy code
def get(self):
    self.session.logging.info(f"Get packet: {self.__class__.__name__}")

    len_header = MAX_PACKET_SIZE
    body = b""
    count_header = 1
    while len_header == MAX_PACKET_SIZE:
        packet_string = self.mysql_socket.recv(4)
        if len(packet_string) < 4:
            self.session.logging.warning(
                f"Packet with less than 4 bytes in length: {packet_string}"
            )
            return False
            break
        len_header = struct.unpack("i", packet_string[:3] + b"\x00")[0]
        count_header = int(packet_string[3])
        if len_header == 0:
            break
        body += self.mysql_socket.recv(len_header)
    self.session.logging.info(f"Got packet: {str(body)}")
    self.proxy.count = int(count_header) + 1
    self.setup(len(body), count_header, body)
    return True


# Traceback (struct.error)
2020-06-25 21:34:22,721 - ERROR - ERROR while executing query: SELECT `rental_price`, `$select_data_query` FROM `demo_rental_price_predictor_mariadb` WHERE $select_data_query= 'SELECT * FROM test.home_rentals limit 1000'
Traceback (most recent call last):
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 805, in handle
self.queryAnswer(sql)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 461, in queryAnswer
return self.selectAnswer(query)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 726, in selectAnswer
self.answerTableQuery(query)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 279, in answerTableQuery
self.sendPackageGroup(packages)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 240, in sendPackageGroup
string = b''.join([x.accum() for x in packages])
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 240, in <listcomp>
string = b''.join([x.accum() for x in packages])
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/data_types/mysql_packet.py", line 92, in accum
string = self.getPacketString()
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/data_types/mysql_packet.py", line 58, in getPacketString
count_header = struct.pack('b', self.seq)
struct.error: byte format requires -128 <= number <= 127

byte format requires -128 <= number <= 127
ERROR:mindsdb_sql:ERROR while executing query: SELECT `rental_price`, `$select_data_query` FROM `demo_rental_price_predictor_mariadb` WHERE $select_data_query= 'SELECT * FROM test.home_rentals limit 1000'
Traceback (most recent call last):
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 805, in handle
self.queryAnswer(sql)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 461, in queryAnswer
return self.selectAnswer(query)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 726, in selectAnswer
self.answerTableQuery(query)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 279, in answerTableQuery
self.sendPackageGroup(packages)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 240, in sendPackageGroup
string = b''.join([x.accum() for x in packages])
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 240, in <listcomp>
string = b''.join([x.accum() for x in packages])
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/data_types/mysql_packet.py", line 92, in accum
string = self.getPacketString()
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/data_types/mysql_packet.py", line 58, in getPacketString
count_header = struct.pack('b', self.seq)
struct.error: byte format requires -128 <= number <= 127

byte format requires -128 <= number <= 127
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 37752)
Traceback (most recent call last):
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 805, in handle
self.queryAnswer(sql)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 461, in queryAnswer
return self.selectAnswer(query)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 726, in selectAnswer
self.answerTableQuery(query)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 279, in answerTableQuery
self.sendPackageGroup(packages)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 240, in sendPackageGroup
string = b''.join([x.accum() for x in packages])
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 240, in <listcomp>
string = b''.join([x.accum() for x in packages])
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/data_types/mysql_packet.py", line 92, in accum
string = self.getPacketString()
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/data_types/mysql_packet.py", line 58, in getPacketString
count_header = struct.pack('b', self.seq)
struct.error: byte format requires -128 <= number <= 127

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.7/socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python3.7/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.7/socketserver.py", line 720, in __init__
self.handle()
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/mysql_proxy.py", line 815, in handle
msg=str(e)
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/data_types/mysql_packet.py", line 86, in send
string = self.getPacketString()
File "/home/george/mindsdb/mindsdb/api/mysql/mysql_proxy/data_types/mysql_packet.py", line 58, in getPacketString
count_header = struct.pack('b', self.seq)
struct.error: byte format requires -128 <= number <= 127
----------------------------------------

# Fixed code
def get(self):
    self.session.logging.info(f"Get packet: {self.__class__.__name__}")

    len_header = MAX_PACKET_SIZE
    body = b""
    count_header = 1
    while len_header == MAX_PACKET_SIZE:
        packet_string = self.mysql_socket.recv(4)
        if len(packet_string) < 4:
            self.session.logging.warning(
                f"Packet with less than 4 bytes in length: {packet_string}"
            )
            return False
            break
        len_header = struct.unpack("i", packet_string[:3] + b"\x00")[0]
        count_header = int(packet_string[3])
        if len_header == 0:
            break
        body += self.mysql_socket.recv(len_header)
    self.session.logging.info(f"Got packet: {str(body)}")
    self.proxy.count = (int(count_header) + 1) % 256
    self.setup(len(body), count_header, body)
    return True