opengridcc / opengrid-dev

Open source building monitoring, analysis and control
Apache License 2.0
26 stars 21 forks source link

Saved houseprint can't be unpickled by python3 #78

Closed saroele closed 8 years ago

saroele commented 8 years ago

For testing, we have a saved housprint object /tests/test_saved_hp.hp. In python2, this can be unpickled without problem, in Python3 this leads to a unicodedecode error. I tried to modify the unpickling as follows:

    with open(filename, 'rb') as f:
        if sys.version_info.major == 3:
            hp = pickle.load(f, encoding='bytes')
        else:
            hp = pickle.load(f)

It loads, but the resulting object is not correct and the subsequent tests fail.

I don't have a python3 machine configured to test. @JrtPec maybe you can solve this? Else we need to get rid of the pickle thing and use a json format for saving/loading houseprint objects?

JrtPec commented 8 years ago

I suspect it might be because you have pickled the object using Python2 and tried to unpickle it using Python3? Have you tried it with an object that was pickled in Python3?

saroele commented 8 years ago

You are probably right. I don't have an object pickled with python3 however. I'll try to create one and test

On Thu, Nov 19, 2015 at 7:26 PM, Jan Pecinovsky notifications@github.com wrote:

I suspect it might be because you have pickled the object using Python2 and tried to unpickle it using Python3? Have you tried it with an object that was pickled in Python3?

— Reply to this email directly or view it on GitHub https://github.com/opengridcc/opengrid/issues/78#issuecomment-158147025.

saroele commented 8 years ago

I solved the issue the hard way: by using jsonpickle instaed of pickle. Works perfectly!