Back

Cloud Function Error. Please check issue ASAP

  • 0
  • Flutter
  • Cloud
Prateek Jain
17 Jul, 2024, 10:23

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 156, in execute output = userModule.main(context) File "/usr/local/server/src/function/main.py", line 39, in main return context.res.json({'result' : result}) 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 bytes is not JSON serializable

TL;DR
Developers are experiencing an error in their cloud function code when trying to return a response. The traceback suggests an issue with serializing a bytes object. Solution: Convert the bytes object to a string before returning it.
Prateek Jain
17 Jul, 2024, 10:24

It was working until 4 days back

Prateek Jain
17 Jul, 2024, 10:26

now app is live...and it is not working suddenly

D5
17 Jul, 2024, 10:44

What's the function code?

D5
17 Jul, 2024, 10:44

Looks like the function is returning an invalid response

Prateek Jain
17 Jul, 2024, 10:52
TypeScript
from appwrite.client import Client
from appwrite.services.databases import Databases
from appwrite.id import ID
from appwrite.exception import AppwriteException
import os

def main(context):
  context.log("hello main")
  client = (
    Client()
    .set_endpoint('https://cloud.appwrite.io/v1')
    .set_project(os.environ['PROJECT_ID'])
    .set_key(os.environ['API_KEY'])
  )
  database = Databases(client)
  try:
    payload = json.loads(context.req.body)
    context.log(str(payload))
    for item in payload:
      try:
        editType = item["editType"]
        if editType == 1 :
          # create document by also specifying collection Ids
          id = item["documentId"] if "documentId" in item else ID.unique()
          result = database.create_document(os.environ['DATABASE_ID'], item["collectionId"] , id, item["data"],)
        elif editType == 2 :
          # update document
          result = database.update_document(os.environ['DATABASE_ID'], item["collectionId"] , item["documentId"], item["data"],)
        else :
          # delete document
          result = database.delete_document(os.environ['DATABASE_ID'], item["collectionId"] ,item["documentId"],)
      except AppwriteException as e:
        context.log(e.message)
  except Exception as e:
    return context.res.json({"success": False, "message": str(e)})
  return context.res.json({'result' : result})```
D5
17 Jul, 2024, 10:58

Maybe your key expired?

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