While trying to run a telemetry python application on Python 3.9, it fails with the error "TypeError: a bytes-like object is required, not 'str'"
Attempting to fix the code by changing 'r' to 'rb' (and 'w' to 'wb') as suggested elsewhere results in a different error.
Unfortunately, I can't figure this one out. Can anyone help me identify the problem here? I'm very new to this. Thanks in advance.
def __init__(self):
try:
with open(STATUS_FILE, 'r') as sfd:
self.st_data = pickle.loads(sfd.read())
except IOError:
self.st_data = dict(seq=0, timestamp=int(time.time()), rx_packets=0, tx_packets=0)
self.st_data['seq'] = (self.st_data['seq'] % 999) + 1
def __repr__(self):
return "%s %s" % (self.__class__, self.st_data)
def save(self):
self.st_data['timestamp'] = int(time.time())
try:
with open(STATUS_FILE, 'w') as sfd:
sfd.write(pickle.dumps(self.st_data))
except IOError as err:
print(err)