1

I am trying to write dataframes to postgres . For that DBAPI used is psycogp2.

localconn='postgresql+psycopg2://postgres/PSWD@localhost:5432/localPG'
localEng=engine.create_engine(localconn)
df.to_sql("DUMMY", localEng)

But its throwing error (psycopg2.OperationalError) could not translate host name postgres to address: Name or service not known

localPG is the database name.

Where I am doing wrong?

1 Answer 1

1

The format you have written is wrong, use the following:

localEng = create_engine('postgresql+psycopg2://[user]:[pass]@[host]:[port]/[schema]', echo=False)

and of course, you should replace every parameter between the bracket with the equivalent database credentials.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot @rachid. I searched a lot.. everywhere the format was same which I used. Anyways it really helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.