nicolemark,

Any #Python devs in the house? I’m getting unpickling error A, which I’ve never seen before. I searched StackOverflow already, obv. It’s esp hard to troubleshoot because it’s in a Jupyter notebook environment controlled by my professor, so I can only change certain parts of the code. TA wasn’t much help—told me to install pickle. 🤦🏼‍♀️

njr,
@njr@zirk.us avatar

@nicolemark I think it means that the scope when the pickle was written had a symbol ‘A’ in scope (maybe a class?) that is not in scope when you are trying to unpickle the file. So it doesn’t know how to use (probably call) A to reconstruct an object.

karlhigley,
@karlhigley@recsys.social avatar

@nicolemark Is it possible that the file was saved with compression (like gzip) or from a library like joblib that has its own code for serialization/pickling? If so, matching the compression settings or reading the file with the same library used to write it may help.

nicolemark,

@karlhigley I would hope our professor didn't do that without telling us, but it's worth looking into, thank you!

kleaders,
@kleaders@fosstodon.org avatar

@nicolemark Does that file work for others with that version of Python? It looks like it is corrupted or just created with a different version of pickle that isn't supported with what you're using.

nicolemark,

@kleaders I don't have control over the environment because it's for a class, and I checed in with a few classmates. Two are having the same problem, but one is not. The one who was able to use it wrote the exact same code as I did.

kimvanwyk,
@kimvanwyk@fosstodon.org avatar

@nicolemark @kleaders are you using the same version of python as your 2 classmates with the same problem? Is your classmate without the problem possibly on a different version of python? The results of pickling can vary across python versions so the version that made the pickle may work but a different version might not.

nicolemark,

@kimvanwyk @kleaders We are all required to be using the same version, and I confirmed that with them.

kimvanwyk,
@kimvanwyk@fosstodon.org avatar

@nicolemark @kleaders rules that out then - I don't suppose one of you is on mac and others on windows or something like that? After that my bad guesses run out unfortunately.

nicolemark,

@kimvanwyk @kleaders We’re all on Macs except one of the other people who couldn’t unpickle the file. They’re a pretty smart and diverse group, experience-wise, so I feel confident at this point that there’s an issue with the file.

kimvanwyk,
@kimvanwyk@fosstodon.org avatar

@nicolemark @kleaders ah, sorry, my apology, from the vagaries of my Mastodon client I didn't realise I was asking a question that had already been asked and answered. Sorry to waste your time!

kleaders,
@kleaders@fosstodon.org avatar

@nicolemark @kimvanwyk yeah I think it's a corrupted file. You can compare the shasums/file sizes on each system to see if something doesn't match up. But the answer probably will be to download again.

slott56,
@slott56@fosstodon.org avatar

@nicolemark how is the file being loaded opened?

nicolemark,

@slott56 I've tried pickle.load and pd.read_pickle

slott56,
@slott56@fosstodon.org avatar

@nicolemark got it. The offending line of code references f an open file. How was this file opened?

nicolemark,

@slott56 I wrote pickle.load(f, 'rb')

slott56,
@slott56@fosstodon.org avatar

@nicolemark which doesn’t seem to match the documentation for pickle.load().

Im reading this https://docs.python.org/3/library/pickle.html#pickle.load

nicolemark,

@slott56 pd.read_pickle, which I’m certain on the syntax of, doesn’t work either 😕

slott56,
@slott56@fosstodon.org avatar

@nicolemark you need to show some more code here. What line of code sets the value for f?

We can’t guess. It’s likely part of the problem.

nicolemark,

@slott56 Thank you for trying to assist. I’m going to be in touch with my professor on Monday.

willmcgugan,
@willmcgugan@mastodon.social avatar

@nicolemark what’s the error?

nicolemark,
nicolemark,

@willmcgugan I tried usind cPickle already

willmcgugan,
@willmcgugan@mastodon.social avatar

@nicolemark haven’t seen that one, but it suggests the data in your pickle file hasn’t been written correctly.

nicolemark,

@willmcgugan That's helpful, thank you!

nobodyinperson,
@nobodyinperson@fosstodon.org avatar

@nicolemark @willmcgugan pickle is quite fragile in my experience, it helps to only use pickled files across identical Python versions. Also, having exactly the same environment / packages on either side is important.

nicolemark,

@nobodyinperson @willmcgugan Yeah, when it works it's great.

eichin,
@eichin@mastodon.mit.edu avatar

@nicolemark
Yeah, pretty sure the A is something in your data (or in what it is treating as your data), it isn't something that you'll find in answers about this.
@willmcgugan

nicolemark,

@eichin @willmcgugan That's helpful. At least I am narrowing down the issue.

eichin,
@eichin@mastodon.mit.edu avatar

@nicolemark @willmcgugan In fact, simple reproduction case:

$ echo -n A > /tmp/pk
$ python3 -c 'import pickle; pickle.load(open("/tmp/pk", "rb"))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
_pickle.UnpicklingError: invalid load key, 'A'.

There are different things an actual pickle will start with, but it looks like a modern one will usually begin with an 0x80 byte and not a printable character. (This probably doesn't narrow it down much further though.)

nicolemark,

@eichin @willmcgugan Thank you! Regardless of whether that narrows it down, I’ve learned several new troubleshooting strategies that I’m saving for later.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • cubers
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • JUstTest
  • everett
  • tacticalgear
  • modclub
  • anitta
  • cisconetworking
  • tester
  • ngwrru68w68
  • GTA5RPClips
  • normalnudes
  • megavids
  • Leos
  • provamag3
  • lostlight
  • All magazines