Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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',
like image 298
Moisizz Avatar asked Jul 17 '14 23:07

Moisizz


1 Answers

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

like image 196
Greg Avatar answered Oct 08 '22 05:10

Greg