This is my python function, and I'm not sure why it fails when run it in console What am I doing wrong?
def main(req, res):
payload = req.payload or 'No payload provided. Add custom data when executing function.'
secretKey = req.variables.get(
'API_KEY_HERE',
'SECRET_KEY variable not found. You can set it in Function settings.'
)
client = Client()
(client
.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
.set_project('PROJECT_ID_HERE') # Your project ID
.set_key('API_KEY_HERE') # Your secret API key
)
databases = Databases(client)
result = databases.create_document('DATABASE_ID_HERE', 'COLLECTION_ID_HERE', 'ID.unique()', {
'Name': 'user123',
'Logo': 'https://images1-fabric.practo.com.png',
'Title': 'title123',
'Location': 'loc1'
},)
return res.json({
'message': 'Hello from Appwrite!',
'payload': payload,
'result': result
})
What is the error? Also maybe the ID shouldn't be a string?
result = databases.create_document('DATABASE_ID_HERE', 'COLLECTION_ID_HERE', ID.unique(), {
'Name': 'user123',
'Logo': 'https://images1-fabric.practo.com.png',
'Title': 'title123',
'Location': 'loc1'
},)
if its outside the string, it says "ID" is not defined
also, in the docs it says string (assuming I'm not misinterpreting it)
Add this at the top of your document
from appwrite.id import ID
Interesting, What is the error you're getting?
there's nothing in errors/ logs
leme try that
failed againπ«
For this also set the ID.unique() as a function?
yeah, did that
Ohh, I'm sorry How did you try to execute the function?
um from the console
In Appwrite or a terminal?
appwrite
Do you any information in any of these tabs?
nope
they just empty
Just want to be sure all the string ends with *_HERE was changed by you for the example, yes?
yeah
Okay, let's try to put all the code inside try/catch block to see what is the exception if there is one.
try:
...your code
except Exception as e:
return res.json({"success": False, "message": str(e)})
After running your code like such you'll be able to see the error message in the Response tab in the console.
okay let me try this
Recommended threads
- Local appwrite run functions --user-id n...
Hi, I'm running into an issue when testing Appwrite functions locally with user impersonation. I'm using a self-hosted Appwrite instance and running functions ...
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Function domain not available
Hello, even tho in docs you clearly describe that every function has its domain, I can not see it anywhere in any of my projects. How do I reveal the url of th...