Moisizz
Moisizz

Reputation: 71

psycopg2 queries to remote database

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',

Upvotes: 7

Views: 15219

Answers (1)

Greg
Greg

Reputation: 6759

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

Upvotes: 11

Related Questions