Back

401 Client Error: Unauthorized

  • 0
  • Databases
  • Accounts
  • Self Hosted
  • Functions
  • Users
Xintie
22 Oct, 2023, 19:16

Hello, I want to create a collection for a specific user, i use this code for python server using Functions but these are errors in functions log:

  • requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://cloud.appwrite.io/v1/databases/65203b010aad5b89b991/collections 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 43, in main result_create_collection = databases.create_collection(db_id, collection_id, f'words_{user_id}', File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/appwrite/services/databases.py", line 138, in create_collection return self.client.call('post', api_path, { File "/usr/local/server/src/function/runtime-env/lib/python3.9/site-packages/appwrite/client.py", line 112, in call raise AppwriteException(response.json()['message'], response.status_code, response.json().get('type'), response.json()) appwrite.exception.AppwriteException: <user_email_hidden> (role: users) missing scope (collections.write)

Code: https://gist.github.com/felicedev/2af899e163d2717465ab8622ae5d85a5

TL;DR
The user is encountering a 401 Client Error: Unauthorized when trying to create a collection for a specific user using Python. The error message indicates that the user's API key does not have the necessary scope for writing to collections. To fix this, the user should use separate client instances - one with the API key and the other with a JWT (JSON Web Token) that has the appropriate scope.
Drake
22 Oct, 2023, 21:03

you should use separate client instances. 1 with api key and the other with JWT

Drake
22 Oct, 2023, 21:03

creating the collection should be done using the client with the api key

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