Back

Asynchronous operations such as querying a database or handling HTTP requests problems

  • 0
  • Web
drake_pham
25 Apr, 2024, 19:55

I have a problem with async appwrite function. I use context in my main function and i call function from query_by_location_id file. However, i got the error. Does anyone have solution for the async function solution? Thank you.

TL;DR
Issue: Error message "Object of type coroutine is not JSON serializable" when trying to return a non-serializable object in an asynchronous function. Solution: The error occurs when trying to return a non-serializable object in an async function. To fix this, ensure that the object being returned is JSON serializable. Check the return values in the `query_by_location_id` and `list_document` functions to guarantee they can be encoded into JSON format.
drake_pham
25 Apr, 2024, 19:55

Hello, Errors! Traceback (most recent call last): File "/usr/local/server/src/server.py", line 163, in action output = await asyncio.wait_for(execute(context), timeout=safeTimeout) File "/usr/local/lib/python3.9/asyncio/tasks.py", line 479, in wait_for return fut.result() File "/usr/local/server/src/server.py", line 154, in execute output = await userModule.main(context) File "/usr/local/server/src/function/main.py", line 51, in main return context.res.json( File "/usr/local/server/src/server.py", line 25, in json return self.send(json.dumps(obj, separators=(',', ':')), statusCode, headers) File "/usr/local/lib/python3.9/json/init.py", line 234, in dumps return cls( File "/usr/local/lib/python3.9/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/local/lib/python3.9/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/usr/local/lib/python3.9/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.class.name} ' TypeError: Object of type coroutine is not JSON serializable

Steven
25 Apr, 2024, 19:57

You're trying to return something that isn't JSON serializable

Steven
25 Apr, 2024, 19:58

Ya. That list_document()

Steven
25 Apr, 2024, 20:00

Or rather, query_by_location_id(location_id)

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more