Skip to content

Keep getting MultiValue not JSON serializable errors #7

@bbearce

Description

@bbearce

Hi,

I'm getting this error when I try to upload my dicom images to couchdb:
"TypeError: Object of type MultiValue is not JSON serializable"
image

What I've done:

  • Installed couchdb via docker.
  • I have Chronicle and couchSite cloned and "working".
  • Using python3.8 I installed couchdb and pydicom
  • Getting error at step: ./bin/record.py <path to dicom data>

Offending line:
couchdb.json.encode(value).encode('utf-8')

My first try at fixing this was to use this advice for casting a MultiValue object to a list:
https://bitbucket.org/openrem/openrem/issues/803
Example:
self.modalities_in_study = json.dumps(x)

Into

self.modalities_in_study = json.dumps(list(x))

Now in this example it was (approx. line: 100 inside a try block):

if isinstance(value, pydicom.multival.MultiValue):
    couchdb.json.encode(list(value)).encode('utf-8')
else:
    couchdb.json.encode(value).encode('utf-8')

This works for a bit but feels hacky. It works until we get to line ~262:
doc_id, doc_rev = self.db.save(document)

Then I get the error again:
image

I've even printed the data to be saved as a document and it's a simple dictionary:
image
...

I don't feel like I should have to edit "couchdb", "json" or "pydicom" to get this to work. Is there something with record.py that I"m configuring wrong? Could it be our data?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions