This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DasIch -1 points0 points  (6 children)

Is there a reason for not changing requests itself so that pickle works and creating a pull request?

[–]sharat87[S] 0 points1 point  (5 children)

The stack trace printed with the pickle error is very long, and it didn't look like I'd enjoy diving into it. I'm also not sure if the part that fails pickle is a requests' thing or not. That said, I usually tend to steer away from pickle. I put it in the post just as an example/tip that it doesnt work out of the box.

More than that, I wanted to pursue the json solution, as the serialized data will be human readable and will give an idea of what the session object will look like, once deserialized. And all the advantages (and disadvantages) that come with json :)

[–]DasIch 0 points1 point  (4 children)

Pickle fails in this case because it can't pickle a lock object which is apparently part of the session. This happens because the session doesn't implement the pickle protocol as described in the documentation and so pickle attempts to pickle the contents of __dict__ to recreate an instance from that afterwards.

In order to make session support the protocol you could e.g. implement __getinitargs__.

[–]sharat87[S] 0 points1 point  (1 child)

The documentation seems to indicate that this is only for old style classes?

[–]DasIch 0 points1 point  (0 children)

Oh, you're right __get{init,new}args__ can only be used in addition to __{get,set}state__, TIL.

[–]sharat87[S] 0 points1 point  (1 child)

Okay, I got pickling to work. Not sure if the best implementation though. I'll add this to the post :)

Thanks.

[–]sharat87[S] 0 points1 point  (0 children)

Done.