Unpickling python2 datetime under python3

前端 未结 1 1541
旧时难觅i
旧时难觅i 2021-01-13 09:52

I chose to use pickle (+base64+TCP sockets) to communicate data between my python3 code and legacy python2 code, but I am having trouble with datetime objects:<

相关标签:
1条回答
  • 2021-01-13 10:05

    The workaround is to use the encoding="bytes" like this:

    pickled_bytes = bytes(pickled_str, encoding='latin1')  # If your input is a string(not my case)
    data = pickle.loads(pickled_bytes, encoding='bytes')
    

    (Thanks to Tim Peters for the suggestion)

    Issue still opened at http://bugs.python.org/issue22005 as to why this is required.

    0 讨论(0)
提交回复
热议问题