1

I have some data stored in Redis which is saved by python app by pickling the data. So basically this is a pickled python dict object. I want to get this stored data in golang. I found a library : https://godoc.org/github.com/hydrogen18/stalecucumber

But when I try some basic example to do unpickling its giving errors like:

string:Pickle Machine failed on opcode:0x62. Stack size:0. Memo size:0. Cause:Stack is too small to perform requested operation
string:Pickle Machine failed on opcode:0x5c. Stack size:0. Memo size:0. Cause:Opcode is invalid

For more clarification refer example given below.

  • Data = pickle.dumps({"apple":1,"banana":2,"cat":"hello","Dog":42.0}) #python pickling
  • Pickled data = b'\x80\x03}q\x00(X\x05\x00\x00\x00appleq\x01K\x01X\x06\x00\x00\x00bananaq\x02K\x02X\x03\x00\x00\x00catq\x03X\x05\x00\x00\x00helloq\x04X\x03\x00\x00\x00Dogq\x05G@E\x00\x00\x00\x00\x00\x00u.'

My try to unpickle in Go:

package main

import (
    "fmt"
    "stalecucumber"
    "io"
    "os"
)    

func main() {
    var pickledDict io.Reader
    var err error
    pickledDict, err = os.Open("file.txt")
    fmt.Println(pickledDict)
    mystruct := struct{
        Apple  int
        Banana uint
        Cat    string
        Dog    float32
    }{}

    err = stalecucumber.UnpackInto(&mystruct).From(stalecucumber.Unpickle(pickledDict))
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(mystruct)
}

Getting Error:

Pickle Machine failed on opcode:0x62. Stack size:0. Memo size:0. Cause:Stack is too small to perform requested operation
{0 0  0}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
skysoft999
  • 540
  • 1
  • 6
  • 27
  • You're ignoring errors. Don't do that. You may well have a problem opening the file, but you'll never know unless you check _all_ your errors. – Jonathan Hall Jun 04 '19 at 08:52
  • I have checked the errors. Can u find any issues here ? i'm a newbie in go @Flimzy – skysoft999 Jun 04 '19 at 11:24
  • Update your code. What do the errors say? – Jonathan Hall Jun 04 '19 at 11:28
  • I have hardcoded pickled data instead of os.Open, still ts giving error. https://play.golang.org/p/kApqin8mY5g – skysoft999 Jun 04 '19 at 11:53
  • Erro MsG: Pickle Machine failed on opcode:0x62. Stack size:0. Memo size:0. Cause:Stack is too small to perform requested operation – skysoft999 Jun 04 '19 at 11:54
  • 2
    The pickle protocol changed between python 2 and 3. The library you are using can only read up to protocol 2 and python 3 defaults to protocol 3. Either take care to pickle using older protocol or better yet use something that is not pickle, like MsgPack or whatever. – Mad Wombat Jun 04 '19 at 15:15

0 Answers0