Back

Value for set_endpoint when using selfhosted appwrite with docker compose

  • 0
  • Self Hosted
  • Functions
Crylog
7 Apr, 2024, 14:05

what is the correct import for query on python sdk ?

TL;DR
Developers are encountering issues with the format of date inputs in Appwrite. The `create_document` API seems more forgiving than the Queries API. The error messages include `400 Client Error: Bad Request` and `500 Server Error: Internal Server Error`, mainly due to incorrect query parameters. The correct format for dates is crucial. To fix the issue, developers should ensure the date format matches what Appwrite expects and consider using the Query helper for creating queries. Additionally, they should double-check the collection ID used.
Crylog
7 Apr, 2024, 14:05

something like from appwrite.query import Query ?

ideclon
7 Apr, 2024, 14:06

I believe so, yes

Crylog
7 Apr, 2024, 14:12

getting a 400 error, so you were 1000% right about set_endpoint being correct and my Querry being wrong, the issue is that it's still wrong x)

Crylog
7 Apr, 2024, 14:12

my code

TypeScript
    for i in collections_id :
        collections_id = collections_id[i]
        result = databases.list_documents(
            database_id="65488cf9e88bc75837bd",
            collection_id=collections_id,
            queries = {
                Query.less_than("date", utc_ytd),
                Query.limit(100),
                Query.offset(0)
            }
        )
Crylog
7 Apr, 2024, 14:13

oh I think I know what's wrong

Crylog
7 Apr, 2024, 14:13

building

Crylog
7 Apr, 2024, 14:16

still no luck

Crylog
7 Apr, 2024, 14:18

code

ideclon
7 Apr, 2024, 14:18

Double check the format of the date, I don’t remember what format is required exactly, but double check it against whatever format is returned.

Crylog
7 Apr, 2024, 14:19

Error :

TypeScript
Hello, Errors!
Traceback (most recent call last):
  File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/appwrite/client.py", line 114, in call
    response.raise_for_status()
  File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/server/src/server.py", line 165, in handler
    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 158, in execute
    output = userModule.main(context)
  File "/usr/local/server/src/function/src/main.py", line 53, in main
    result = databases.list_documents(
  File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/appwrite/services/databases.py", line 916, in list_documents
    return self.client.call('get', api_path, {
  File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/appwrite/client.py", line 129, in call
    raise AppwriteException(response.json()['message'], response.status_code, response.json().get('type'), response.json())
appwrite.exception.AppwriteException: Server Error
Crylog
7 Apr, 2024, 14:21

on the app sending log to database (which also use the python sdk)

i've used (and it worked) :

TypeScript
  current_date = datetime.now()
  current_date = current_date.isoformat()
  res = database.create_document("collection_id", i[1], ID.unique(), {"raw_json" : logs[i[0]]["raw_json"], "date" : current_date})
ideclon
7 Apr, 2024, 14:24

Yeah, I think the create_document() API is more forgiving than the Queries API

ideclon
7 Apr, 2024, 14:25

Before changing the Queries you were getting a 400 and now you’re getting a 500? Or the other way around?

Crylog
7 Apr, 2024, 14:25

400 then 500

Crylog
7 Apr, 2024, 14:26

the 400 error was :

TypeScript
Hello, Errors!
Traceback (most recent call last):
  File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/appwrite/client.py", line 114, in call
    response.raise_for_status()
  File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/server/src/server.py", line 165, in handler
    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 158, in execute
    output = userModule.main(context)

  File "/usr/local/server/src/function/src/main.py", line 53, in main
    result = databases.list_documents(
  File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/appwrite/services/databases.py", line 916, in list_documents
    return self.client.call('get', api_path, {
  File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/appwrite/client.py", line 129, in call
    raise AppwriteException(response.json()['message'], response.status_code, response.json().get('type'), response.json())
appwrite.exception.AppwriteException: Invalid `queries` param: Value must a valid array and Value must be a valid string and at least 1 chars and no longer than 4096 chars
Crylog
7 Apr, 2024, 14:27

I switched from a dict to an array

ideclon
7 Apr, 2024, 14:27

Yeah, you can see at the end there Invalid ‘queries’ param

ideclon
7 Apr, 2024, 14:28

So double check that the date you’re passing in is in exactly the format Appwrite returns the date in

Crylog
7 Apr, 2024, 14:31

'2023-12-10T20:58:29.506+00:00'

Crylog
7 Apr, 2024, 14:32

the format is different from the one used in the document_create

ideclon
7 Apr, 2024, 14:35

Yeah, as I said earlier, document_create() is fairly forgiving of date input formats. Queries are not.

Crylog
7 Apr, 2024, 14:35

(i used document_list without the query to know what is the real date format in the db)

Crylog
7 Apr, 2024, 14:36

create_document use ISO 8601, what is the name of the format used for query ?

ideclon
7 Apr, 2024, 14:37

Whatever is returned by Appwrite - I don’t remember what the standard is.

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