#๐Ÿ”’ OperationalError: could not translate host name "not gonna show host name" to address: No such hos

20 messages ยท Page 1 of 1 (latest)

whole sage
#

so im trying to connect to a cloud postgreSQL that is made with render and its not connecting but im sure host name is correct. heres some code. def get_db_connection():
try:
conn = psycopg2.connect(
dbname=" ",
user=" ",
password=" ",
host=" ",

    )
    print("Database connection successful!")
    return conn
except psycopg2.OperationalError as e:
    print(f"OperationalError: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")
return None

def save_chat_to_db(user_id, message, role):
conn = get_db_connection()
if conn is None:
print("Failed to connect to the database.")
return

steel saffronBOT
#

@whole sage

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

craggy pine
#

You sure you're using the external url and not the internal one?

whole sage
#

how do i know that

craggy pine
#

when you copied the URL from render, it has an internal one and an external one.

whole sage
#

my friend made it ill ask her thank u

craggy pine
#

sure thing

#

I would bet money that's the issue

whole sage
craggy pine
#

probably not. You can get to render.com on the computer you're running your python from?

whole sage
#

u mean her account on render? i dont have it and im not smart with database

craggy pine
#

no I just mean can you go to render.com in your browser?

whole sage
#

ofc

craggy pine
#

then you should be able to resolve the URL for your DB connection

#

so yeah, she probably just sent over the wrong one

flat lagoon
#

On the machine where the script is running, type host the-hostname-here, that should look it up. I don't know if that works in windows, it's a UNIX command. Basicly, you want to test DNS lookup of the host name in the environment where the script is being run.

steel saffronBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.