Skip to content
Back

Python: Appwrite Cloud, Server Function appwrite.exception.AppwriteException: request cannot have re

  • 0
  • Databases
  • Functions
  • Cloud
S.Rottgardt
17 Apr, 2025, 10:57

Im getting the following error on appwrite cloud. Error creating document: AppwriteException('request cannot have request body') python requirements.txt -> appwrite ( so the latest)

`import traceback from appwrite.client import Client from appwrite.services.databases import Databases from appwrite.exception import AppwriteException from appwrite.query import Query import os import json

def main(context): client = ( Client() .set_endpoint(os.environ["APPWRITE_FUNCTION_API_ENDPOINT"]) .set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"]) .set_key(context.req.headers["x-appwrite-key"]) )

TypeScript
databases = Databases(client)

collection_id = "67c589d00037795558a0"
user_data_collection_id = "6761602b003df9df3661"
database_id = "67615fe8003a2b1eaebf"
user_id = context.req.headers.get("x-appwrite-user-id", None)

if not user_id:
    return context.res.json({"error": "Not a valid action"}, 400)

try:
    if not context.req.body_json:
        return context.res.json({"error": "No data provided"}, 400)

    try:
        data = context.req.body_json
    except json.JSONDecodeError:
        return context.res.json({"error": "Invalid JSON format"}, 400)
    
    firstName = data.get("firstName")
    lastName = data.get("lastName")
    email = data.get("email")
    profilImage = data.get("profilImage")
    context.log(f"Firstname: {firstName}")
    context.log(f"Lastname: {lastName}")
    context.log(f"Email: {email}")
    context.log(f"ProfilImage: {profilImage}")
    if not all([firstName, lastName, email, profilImage]):
        context.error("Missing required fields")
        return context.res.json({"error": "Missing required fields"}, 400)

    documents = databases.list_documents(
        database_id=database_id,
        collection_id=user_data_collection_id,
        queries=[Query.equal("userId", user_id)]
    )`
TL;DR
Developers are encountering the error `appwrite.exception.AppwriteException: request cannot have request body` while using Python with Appwrite Cloud. The issue arises when creating a document due to incorrect request handling. Debug the code to ensure the request body is being processed correctly and handle error cases appropriately.
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