+2 votes
795 views
Hi,

When I do this :

> unit_ref = client.find(olca.Unit, "kg")
> unit = client.get(olca.Unit, unit_ref.id)

I get a "500: Conversion to JSON failed". This is not the case with other types, like UnitGroup.

I tried to debug printing requests responses but without success.
in openLCA by (700 points)

1 Answer

+1 vote
by (14.0k points)
selected by
 
Best answer

Correct, the `get` and `find` methods currently only work with stand-alone entities. Stand-alone entities are basically the things that you can find in the navigation tree of openLCA. As a unit is always part of a unit group it is not a stand-alone entity. You should be able to get it via the unit group:

>>> import olca
>>> client = olca.Client(8080)
>>> group_ref = client.find(olca.UnitGroup, "Units of mass")
>>> group = client.get(olca.UnitGroup, group_ref.id)
>>> kg = [u for u in group.units if u.name == "kg"]
>>> kg
[<olca.schema.Unit object at 0x000001A2672D7070>]

However, getting a unit via the IPC client would be of course useful. I added an issue for this on the IPC repo: https://github.com/GreenDelta/olca-ipc.py/issues/4

by (700 points)
Thanks for the answer and the created issue, the code you provided is what I did myself :)
...