Value for set_endpoint when using selfhosted appwrite with docker compose
- 0
- Self Hosted
- Functions

what is the correct import for query on python sdk ?

something like from appwrite.query import Query ?

I believe so, yes

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)

my code
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)
}
)

oh I think I know what's wrong

building

still no luck

code

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.

Error :
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

on the app sending log to database (which also use the python sdk)
i've used (and it worked) :
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})

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

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

400 then 500

the 400 error was :
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

I switched from a dict to an array

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

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

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

the format is different from the one used in the document_create

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

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

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

Whatever is returned by Appwrite - I don’t remember what the standard is.
Recommended threads
- deno 2 Cloud random errors
we have big problems with the functions. although we do not change anything in the function, we have the following random behaviour: - no scope permissions erro...
- Functions not work on Server only Localh...
Hi, I successfully upgraded from 1.4 to 1.7, but I'm having a problem. The functions no longer work with the settings I had. I assume some changes were made. It...
- Console Login after upgrade
Hi, running a small instance self hosted, upgraded from 1.6.0 to 1.74 this morning before spotting the migration guide... When trying to login to the console n...
