Code works on python2 not python3 (compressString)

Hi everyone! I’m having a bit of trouble trying to get a script I’m working on to function on the equivalent version of Panda3D when using Python3.

This code works perfectly on Python2, but completely falls apart when used with Python3.
The error:

“UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xa4 in position 2: invalid start byte”

Thanks!

from direct.showbase.ShowBase import ShowBase
from panda3d.core import *

class compressExampleA(ShowBase):
 
    def __init__(self):
        ShowBase.__init__(self)
 
        self.scene = self.loader.loadModel("panda")
        self.scene.reparentTo(self.render)
        self.scene.setScale(0.25)
        self.scene.setPos(-8, 42, 0)
 
        ss = StringStream()
        self.scene.writeBamStream(ss)
        ssdata = ss.getData()

        data = compressString(ssdata, 1) # Why won't this work on Python 3?
        print (data)

app = compressExampleA()
app.run()

Hello. I can’t exactly tell why this function is not working, probably it is better to ask the engine maintainers.
As far as I understand, getData() returns str with Python 2, and bytes with Python 3.

Maybe you can use a workaround. This function looks like it just a wrapper around zlib library. You can compress your scene data with the standard Python function:

import zlib
zlib.compress(ssdata, 1)

I concur that the zlib module may be an adequate replacement.

As for fixing this in Panda, perhaps we need a compress_bytes function that operates on a bytes object, but since the zlib module duplicates this functionality, I’m wondering if there is much of a need to continue to offer this API in Panda.

Thank you guys for responding, that did help me get over the hump I was stuck on.