The goals is to synchronize users to database. How can I get some result code from the get document SDK of Python?
TypeScript
from appwrite.services.users import Users
from appwrite.services.databases import Databases
import os
def main(context):
client = (
Client()
.set_endpoint("https://cloud.appwrite.io/v2")
.set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"])
.set_key(os.environ["APPWRITE_API_KEY"])
)
users = Users(client)
databases = Databases(client)
result = users.list()
for data in result["users"]:
result = databases.get_document(os.environ["DATABASE_ID"], os.environ["COLLECTION_ID"], data["$id"])
if result.code == 404:
# create some document
# databases.create_document('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]', {})```
TL;DR
The user wants to know how to get a result code from the get document SDK of Python using the Appwrite server SDK. They are trying to synchronize users to a database. The solution is to use a try-except block and check the result code for a specific value, such as 404. If the result code is 404, the user can proceed to create a new document.Solved, by try except
[SOLVED] How to get result code from Python server SDK
Recommended threads
- I recently switched to TablesDb. When li...
olddb.list_documents( queries =[ Query.order_desc("timestamp"), Query.equal("isPosted",[False]) ] ) Above works fine and reruns documents But below don't return...
- Database error validating 'min' and 'max...
I keep seeing an error when I try to add a column to a database table within the AppWrite cloud UI. I also see this error when trying to create or update a reco...
- Fine grained permissions for webRTC hand...
Hi, I am building a WebRTC P2P app for a university project and have hit a security limitation regarding permissions for anonymous users. The Architecture: We ...