Question

Unable to connect with Postgres Database From Serverless Function in Python

I have a simple server less function that is simply doing a select query to a PostgreSQL database hosted on digital ocean in Python using SQLAlchemy, but it is sending { “code”: “9d5872ba17cd438c844b05a5fe6a5450”, “error”: “There was an error processing your request.” } on line engine = create_engine(POSTGRES_DB_URL)

I am feeling dead end at this point.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Jon Friesen
DigitalOcean Employee
DigitalOcean Employee badge
January 11, 2023

Hi SalmanZ10

There are a few things that could be causing the error you’re seeing. Here are a few things you can check to help debug the issue:

  1. Make sure that the PostgreSQL database you’re trying to connect to is up and running, and that you can connect to it using the connection details specified in the POSTGRES_DB_URL variable.

  2. Check the permissions for the user specified in the POSTGRES_DB_URL. Make sure that the user has the appropriate permissions to run SELECT queries on the database.

  3. Check the application logs for more detailed information about the error. The logs may give more insight into the specific issue.

  4. Verify the POSTGRES_DB_URL. Make sure that the url is valid, with the correct database name, host, port,user and password in it.

  5. Try to see if the same code is working as expected on your local environment, as the error could be with the setup of the service on digital ocean’s app platform.

I hope this helps you to resolve the issue. If you need further assistance, please let me know.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up