8000 Keep getting MultiValue not JSON serializable errors · Issue #7 · pieper/Chronicle · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Keep getting MultiValue not JSON serializable errors #7

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

Open
bbearce opened this issue Apr 23, 2020 · 1 comment
Open

Keep getting MultiValue not JSON serializable errors #7

bbearce opened this issue Apr 23, 2020 · 1 comment

Comments

@bbearce
Copy link
Contributor
bbearce commented Apr 23, 2020

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?

@pieper
Copy link
Owner
pieper commented Apr 24, 2020

Hi -

Thanks for reporting 👍

These are probably issues related to python3 and pydicom 1.x. As I recall the code originally was written against python2.x and pydicom 0.9.x, so maybe one easy workaround would be to install these and try again (they should be pretty easy to find and specify in the paths).

Beyond that, it would be better to fix this code to use the up-to-date packages. The json conversion code from chronicle was actually extracted from here and contributed to the upstream pydicom repository (see pydicom/pydicom#862) and that pull request is where a lot of the porting took places.

So probably the best solution overall would be to find a way to switch over to using the new pydicom json converters as described here:
https://pydicom.github.io/pydicom/stable/tutorials/dicom_json.html

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

No branches or pull requests

2 participants
0