AssetReport is not returning JSON object
rajeshsachin10 opened this issue · 6 comments
We are facing issue with asset report pull, where we are using "/asset_report/get" endpoint to receive the response as JSON (https://plaid.com/docs/api/products/#asset_reportget). As per the documentation it must return a JSON documentation ("The /asset_report/get endpoint retrieves the Asset Report in JSON format"), but we are receiving the error "Object of type AssetReport is not JSON serializable". We are using "python-plaid" (https://github.com/plaid/plaid-python) version 8.0.0.
ERROR:root:Exception while retrieving asset report from Plaid for asset_report_id 0dd3e546-6f5a-45ca-9baf-93a4a6848b61. Error : Object of type AssetReport is not JSON serializable
Traceback (most recent call last):
File "/Users/rrprabha/Rajesh/jagdish/aws_codecommit/nrilab-api/service/plaid_svc.py", line 252, in get_and_store_asset_report_svc
asset_report=json.dumps(report))
File "/usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/init.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type AssetReport is not JSON serializable
The issue with the asset response are they contain single quotes (') in json response which is not a valid json.
https://www.json.org/json-en.html
A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.
@rajeshsachin10 does this still happen if you use the latest release (8.4.0)?
Yes. I have updated the version to use 8.4.0 and got the below error. Still the response have single quotes.
Error : cannot encode object: {'asset_report_id': '404117da-ad51-4a7f-8683-932cebb7e40f',
'client_report_id': '92e3a6e0-f9ee-484d-97a3-586602a2e034',
'date_generated': datetime.datetime(2021, 9, 30, 6, 13, 25, tzinfo=tzutc()),
'days_requested': 60.0,
of type: <class 'plaid.model.asset_report.AssetReport'>
@rajeshsachin10 a very similar question was recently posted on Stack Overflow -- check out Stephen's answer and let us know if it solves your problem? https://stackoverflow.com/questions/69621991/how-can-i-load-a-plaid-banking-api-response-to-a-pandas-dataframe-in-python
Hi. I have tried the solution discussed in the above thread. But we are still facing the below issue with it.
Error : cannot encode object: datetime.date(2021, 8, 3), of type: <class 'datetime.date'>
Ous use case is to download the response as json and store them in mongodb using pymongo. Looks like the above issue is discussed in https://stackoverflow.com/questions/30553406/python-bson-errors-invaliddocument-cannot-encode-object-datetime-date2015-3 and looks like lot of custom converstion needs to be perfomed on the response recived to store them as json in mongodb. Is there as way these response provide a pymongo compatible values back?
any update on this?
we've since added documentation to the README to address how to handle date-time formats, so I'm going to close this one out as the behavior seems to be working as expected. Feel free to open another issue if you are still experiencing problems!