'function' object has no attribute 'dumps'

1.1k Views Asked by At

I imported pickle from copyreg. I then use the attribute dumps to convert a dictionary into bytes b'\x80\x04...' but it results in the error shown below:

from copyreg import pickle
d={"name":value}
d=pickle.dumps(d)

Error:

AttributeError: 'function' object has no attribute
2

There are 2 best solutions below

0
On

I imported from the wrong library. The code should have been:

import pickle
d={...}
d=pickle.dumps(d)
0
On

Your import seems incorrect. It should be:

from pickle import dumps

d = {..}
d = dumps(d)