# Buggy code
def getPacketString(self):
    body = self.body
    len_header = struct.pack("<i", self.length)[:3]  # keep it 3 bytes
    count_header = struct.pack("b", self.seq)
    packet = len_header + count_header + body
    return packet


# 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 getPacketString(self):
    body = self.body
    len_header = struct.pack("<i", self.length)[:3]  # keep it 3 bytes
    count_header = struct.pack("B", self.seq)
    packet = len_header + count_header + body
    return packet