I need to get some data from remote database. Here code to connect:
import psycopg2
params = {
'dbname': 'some_db',
'username': 'user',
'password': 'password',
'host': '333.333.333.333',
'port': 3333
}
conn = psycopg2.connect(**params)
Then i try to execute query:
cur = conn.cursor()
cur.execute("SELECT * FROM sometable")
And after that i get exception:
psycopg2.ProgrammingError: relation sometable does not exist
Now if i connect to database with exact same parameters from same machine via psql:
psql --dbname=some_db --username=user --password=password --host=333.333.333.333 --port=3333
and try to execute query:
SELECT * FROM sometable;
i get results without any errors. And it happens not only with one table, but with all of them in that database.
EDIT
I have little mistake in params. I use not
'username': 'user',
but:
'user': 'user',
Try connecting with different variable names, like:
params = {
'database': 'some_db',
'user': 'user',
'password': 'password',
'host': '333.333.333.333',
'port': 3333
}
See:
http://initd.org/psycopg/docs/module.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With