Back

Listing documents inside a function – "Http invalid protocol"

  • 0
  • Functions
Baudouin Arbarétier
15 Oct, 2023, 23:05

Hi – I'm trying to port my old functions to the new 1.4.5 way.

I manage to get a simple working function that simply sends back a string.

However, I can't manage to make my function list some documents and send them back.

It seems that the appwrite client is able to connect, but as soon as I include code to query the database it just gets a 500 error without any logs except : An internal curl error has occurred within the executor! Error Msg: Http invalid protocol\nError Code: 500

Here is a minimal version of my not working code, maybe I forgot something..

TypeScript
def main(context):
    # Setup client
    client = Client()
    endpoint = "https://devback.banquise.app/v1"
    project_id = os.environ['APPWRITE_FUNCTION_PROJECT_ID']
    api_key = os.environ["APPWRITE_FUNCTION_API_KEY"]
    
    client.set_endpoint(endpoint).set_project(project_id).set_key(api_key)

    # Log environment variables
    context.log(project_id)
    context.log(api_key)

    # Initialize database
    database = Databases(client)

    # Fetch user ID from header
    user_id = context.req.headers["x-appwrite-user-id"]
    context.log(user_id)

    # Get payload from request body
    payload = context.req.body
    context.log(payload)

    # Fetch and send the feed
    try:
        final_feed = database.list_documents('62e0fd2xxxxxxx', '62e0fe08axxxxxxxx')["documents"]
        context.log(final_feed)
        return context.res.send(str(final_feed))
    except Exception as e:
        context.error(e)
        return context.res.send(e, 500)

Thank you by advance!

TL;DR
The user is experiencing an "operation timed out" error after making changes to their script. They tried converting the error to a string and removing the 500 status code, but the error still persists. The user is trying to list documents and send them back using the Appwrite client, but they are receiving a 500 error with the message "Http invalid protocol". They have shared a minimal version of their code.
Drake
16 Oct, 2023, 05:43

Try wrapping the error withstr(e) to convert to string.

Also can you try leaving the 500 status code out?

Baudouin Arbarétier
16 Oct, 2023, 06:46

Thanks for your answer, so I tried changing the script to this :

TypeScript
try:
        final_feed = database.list_documents('62e0fd281976e7171db9', '62e0fe08a4a5d6592df2')["documents"]
        context.log(final_feed)

        return context.res.send(str(final_feed))

    except Exception as e:
        context.log(e)
        return context.res.send(str(e))

But now it gives me an "operation timed out" error.

Any ideas ?

Baudouin Arbarétier
16 Oct, 2023, 17:51

tried lots of different configurations... it's still happening – any ideas ?

xue
16 Oct, 2023, 22:55
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