#[Solved] Functions: error trying to retrieve request body (Python runtime)

11 messages · Page 1 of 1 (latest)

hexed shadow
#

Hi i'm writing a python functions and i need to retrieve request body.

Server: Appwrite cloud.
CLI: 6.0.0
The Functions is in local dev with Appwrite CLI.

I find this code snippet in functions doc:

import json

def main(context):
    context.log(context.req.bodyText)              # Raw request body, contains request data

(Source: https://appwrite.io/docs/products/functions/develop#request)

but if i try it, i receive:

context.log(context.req.bodyRaw)              # Raw request body, contains request data
AttributeError: 'Request' object has no attribute 'bodyRaw'

This is Postman body view:

Master serverless function development with Appwrite. Learn how to write and test functions locally, debug code, and optimize for efficient execution.

fervent thunder
#

Use req.bodyRaw, Cloud is still on 1.5.10 while the docs point to the 1.6.x release.

#

basically use the deprecated methods on cloud.

hexed shadow
#

I had tried with the previous version but:

#

where:

req = context.req
context.log(req.bodyRaw)
fervent thunder
#

You seem to be using the CLI local development, I don't think it might be compatible with 1.5.10. @rough igloo is it though?

hexed shadow
#

Yes, I am using local CLI development to test the function before loading it.
I didn't find anything in the doc about version incompatibilities appwritemandancing

hexed shadow
#

Is there no solution? 😦

#

I created a new function using node 16, here instead there is no problem taking the body of the function.

export default async ({ req, res, log }) => {
  log(req.bodyText); 
};
{
    "user_id" : "XXXX",
    "labels" : ["lab.2", "lab.1"]
}
rough igloo
hexed shadow
#

Thanks, I'll try