Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save WhistleBlowerDict obj. (or an object with nested WhistleBlowerDict) to a pickle. #172

Closed
Quodzik opened this issue Dec 17, 2023 · 3 comments · Fixed by #175

Comments

@Quodzik
Copy link

Quodzik commented Dec 17, 2023

When I'm saving a custom class instance to a pickle file, there's no error, file is being generated in the filesystem.
I do this with:
pickle.dump(proc_db, open('process_db_vted.pickle', 'wb'))
I have also tried changing default arguments (protocol=pickle.HIGHEST_PROTOCOL and fix_imports=True).

When trying to load the pickle file with:
proc_db = pickle.load(open('process_db_vted.pickle', 'rb'))
I get:

    proc_db = pickle.load(open('process_db_vted.pickle', 'rb'))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\venv\Lib\site-packages\vt\object.py", line 39, in __setitem__
    self._on_change_callback()
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WhistleBlowerDict' object has no attribute '_on_change_callback'

please advise
Regards,
Q

@mgmacias95
Copy link
Member

Hello @Quodzik,

I have tried to reproduce your error but I've been unable to do it. This is the steps I've taken:

>>> import vt
>>> a = vt.Client('a')
>>> a
<vt.client.Client object at 0x1026d29d0>
>>> import pickle
>>> b = pickle.dumps(a)
>>> b
b'\x80\x04\x95\xb8\x00\x00\x00\x00\x00\x00\x00\x8c\tvt.client\x94\x8c\x06Client\x94\x93\x94)\x81\x94}\x94(\x8c\x05_host\x94\x8c\x1ahttps://www.virustotal.com\x94\x8c\x07_apikey\x94\x8c\x01a\x94\x8c\x06_agent\x94\x8c\x07unknown\x94\x8c\x08_session\x94N\x8c\n_trust_env\x94\x89\x8c\x08_timeout\x94M,\x01\x8c\x06_proxy\x94N\x8c\r_user_headers\x94N\x8c\x0b_verify_ssl\x94\x88ub.'
>>> c = pickle.loads(b)
>>> c
<vt.client.Client object at 0x1026d35d0>

Can you provide more accurate steps to reproduce the problem?

Thanks.

@Quodzik
Copy link
Author

Quodzik commented Dec 18, 2023

Hi @mgmacias95,
thanks for your reply. That's exactly what I wanted to share, but I didn't have a change to do that. Here's a short script that generates an error, when I run it:

import pickle
import vt

md5hash = 'e60295d4d202496c1d689343bb58c9e0'

api_key = 'xxxxxxxxxxxxxx'
client = vt.Client(api_key)

vt_data = client.get_object(f'/files/{md5hash}')

#save vt_data to file
with open('vt_data.pickle', 'wb') as f:
    pickle.dump(vt_data, f)

#load vt_data from file
with open('vt_data.pickle', 'rb') as f:
    vt_data = pickle.load(f)

Thanks

@mgmacias95
Copy link
Member

Hello @Quodzik,

I have made a fix for this issue at #175. As soon as it's merged we'll release a new version with the fix.

Thanks!

Regards,
Marta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants