Reputation: 385
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?
Upvotes: 1
Views: 234
Reputation: 2496
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.
Upvotes: 1