Back

[SOLVED] How to run SDK modules within functions?

  • 0
  • Databases
  • Functions
  • Web
Marcelo Delta
21 Dec, 2023, 02:33

I created a function within appWrite to try to read a document. However, I come across a problem that does not show an error and the script stops working in the get_document query.

What address to access the database, for example, within an AppWrite function?

TypeScript
client = Client()
    (client
    .set_endpoint('http://127.0.0.1/v1')
    .set_project('657da51f0...')
    .set_key('cf2c393c430...')
    )

documento = databases.get_document('657da5305d...', '657da6499df6...', context.req.body["documentId"])

Error
appwrite.exception.AppwriteException: HTTPConnectionPool(host='127.0.0.1', port=80):
TL;DR
The user was trying to run SDK modules within functions in Appwrite but encountered a problem. They received an error message indicating a connection issue to the database. Another user suggested setting the endpoint to the local IP with port 8090, but the user confirmed that they were already using Appwrite on port 8090. The problem seemed to be with executing the `set_endpoint` function inside the function. The user also mentioned that they had another service using port 80. Finally, the user shared the error message they received and asked for the correct address to access the database within an AppWrite function. Solution: The user received a connection
Marcelo Delta
21 Dec, 2023, 02:54

Did not work.

I tried with port 80 and the port we are using is 8090

appwrite.exception.AppwriteException: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /v1/databases/657da5305d3da8c5e/collections/657da6499df6b9f9/documents/6582834d7b559ee6d0 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f98bc3e4220>: Failed to establish a new connection: [Errno 111] Connection refused'))

appwrite.exception.AppwriteException: HTTPConnectionPool(host='localhost', port=8089): Max retries exceeded with url: /v1/databases/657da5305d3da8c5e/collections/657da6499df6b9f9/documents/6582834d7b559ee6d0 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f98bc3e4220>: Failed to establish a new connection: [Errno 111] Connection refused'))

Drake
21 Dec, 2023, 02:55

That's not what was suggested

Drake
21 Dec, 2023, 02:56

And for the port it depends on what port you selected when installing Appwrite

Marcelo Delta
21 Dec, 2023, 02:57

We are using appwrite on port 8090 and it is working well for all other features.

Because we have another service using port 80

Only in this scenario to execute set_endpoint inside the function is the problem.

Drake
21 Dec, 2023, 02:57

So use port 8090

Marcelo Delta
21 Dec, 2023, 02:58

We've tried it and it doesn't work.

I sent the result above using port 8090 as well

Drake
21 Dec, 2023, 02:58

What exactly are you reading from what I shared?

Marcelo Delta
21 Dec, 2023, 03:00
Drake
21 Dec, 2023, 03:01

Good...

Marcelo Delta
21 Dec, 2023, 03:05

Includes the local IP and it worked

Marcelo Delta
21 Dec, 2023, 03:06

Thanks again Steven.

We are making great progress in using all Appwrite features on our Intranet.

Drake
21 Dec, 2023, 03:18

[SOLVED] How to run SDK modules within functions?

Drake
21 Dec, 2023, 03:18

Good to hear!

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