sdementen / piecash

Pythonic interface to GnuCash SQL documents
Other
290 stars 73 forks source link

Some problem to connect postgres DB #144

Closed EuPhobos closed 3 years ago

EuPhobos commented 4 years ago

I'm trying simple script: $ cat pietest.py import piecash book = piecash.open_book(uri_conn="postgres://prot:pass123@10.50.50.12/test") for account in book.accounts: print(account) The database is "test" but i have error: FATAL: no pg_hba.conf entry for host "10.50.50.1", user "prot", database "postgres", SSL off

Then when im trying update pip packages, i get this: piecash 1.1.2 has requirement SQLAlchemy-Utils!=0.36.8, but you'll have sqlalchemy-utils 0.36.8 which is incompatible.

I also check: $ grep SQLAlchemy requirements-dev.txt SQLAlchemy==1.3.20 SQLAlchemy-Utils==0.36.8 in requirements-dev.txt - SQLAlchemy-Utils==0.36.8 Then i found closed similar issue: https://github.com/sdementen/piecash/issues/91 I downgrade SQLAlchemy-Utils to 0.36.7 but still no luck, same error about database "postgres", but not "test" as URI set..

EuPhobos commented 4 years ago

The full output: ` $ python3 ./pietest.py Traceback (most recent call last): File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 2338, in _wrap_pool_connect return fn() File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 364, in connect return _ConnectionFairy._checkout(self) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 778, in _checkout fairy = _ConnectionRecord.checkout(pool) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 495, in checkout rec = pool._do_get() File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/impl.py", line 140, in _do_get self._dec_overflow() File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/util/langhelpers.py", line 69, in exit exc_value, with_traceback=exc_tb, File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x8664.egg/sqlalchemy/util/compat.py", line 182, in raise raise exception File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/impl.py", line 137, in _do_get return self._create_connection() File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 309, in _create_connection return _ConnectionRecord(self) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 440, in init self.connect(first_connect_check=True) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 661, in __connect pool.logger.debug("Error on connect(): %s", e) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/util/langhelpers.py", line 69, in exit exc_value, with_traceback=exc_tb, File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x8664.egg/sqlalchemy/util/compat.py", line 182, in raise raise exception File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 656, in connect connection = pool._invoke_creator(self) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 114, in connect return dialect.connect(*cargs, *cparams) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/default.py", line 493, in connect return self.dbapi.connect(cargs, cparams) File "/home/prot/.local/lib/python3.7/site-packages/psycopg2/init.py", line 127, in connect conn = _connect(dsn, connection_factory=connection_factory, kwasync) psycopg2.OperationalError: FATAL: no pg_hba.conf entry for host "10.50.50.1", user "prot", database "postgres", SSL on FATAL: no pg_hba.conf entry for host "10.50.50.1", user "prot", database "postgres", SSL off

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "./pietest.py", line 3, in book = piecash.open_book(uri_conn="postgres://prot:pass123@10.50.50.12/test") File "/home/prot/.local/lib/python3.7/site-packages/piecash/core/session.py", line 368, in open_book if check_exists and not database_exists(uri_conn): File "/usr/local/lib/python3/dist-packages/SQLAlchemy_Utils-0.36.7-py3.7.egg/sqlalchemy_utils/functions/database.py", line 471, in database_exists return bool(get_scalar_result(engine, text)) File "/usr/local/lib/python3/dist-packages/SQLAlchemy_Utils-0.36.7-py3.7.egg/sqlalchemy_utils/functions/database.py", line 445, in get_scalar_result result_proxy = engine.execute(sql) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 2236, in execute connection = self._contextual_connect(close_with_result=True) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 2304, in _contextual_connect self._wrap_pool_connect(self.pool.connect, None), File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 2342, in _wrap_pool_connect e, dialect, self File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1584, in _handle_dbapi_exception_noconnection sqlalchemy_exception, with_traceback=excinfo[2], from=e File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x8664.egg/sqlalchemy/util/compat.py", line 182, in raise raise exception File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 2338, in _wrap_pool_connect return fn() File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 364, in connect return _ConnectionFairy._checkout(self) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 778, in _checkout fairy = _ConnectionRecord.checkout(pool) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 495, in checkout rec = pool._do_get() File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/impl.py", line 140, in _do_get self._dec_overflow() File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/util/langhelpers.py", line 69, in exit exc_value, with_traceback=exc_tb, File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x8664.egg/sqlalchemy/util/compat.py", line 182, in raise raise exception File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/impl.py", line 137, in _do_get return self._create_connection() File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 309, in _create_connection return _ConnectionRecord(self) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 440, in init self.connect(first_connect_check=True) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 661, in __connect pool.logger.debug("Error on connect(): %s", e) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/util/langhelpers.py", line 69, in exit exc_value, with_traceback=exc_tb, File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x8664.egg/sqlalchemy/util/compat.py", line 182, in raise raise exception File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/pool/base.py", line 656, in connect connection = pool._invoke_creator(self) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/strategies.py", line 114, in connect return dialect.connect(*cargs, *cparams) File "/usr/local/lib/python3/dist-packages/SQLAlchemy-1.3.19-py3.7-linux-x86_64.egg/sqlalchemy/engine/default.py", line 493, in connect return self.dbapi.connect(cargs, cparams) File "/home/prot/.local/lib/python3.7/site-packages/psycopg2/init.py", line 127, in connect conn = _connect(dsn, connection_factory=connection_factory, kwasync) sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: no pg_hba.conf entry for host "10.50.50.1", user "prot", database "postgres", SSL on FATAL: no pg_hba.conf entry for host "10.50.50.1", user "prot", database "postgres", SSL off

(Background on this error at: http://sqlalche.me/e/13/e3q8) `

sdementen commented 4 years ago

Sorry, haven't seen your issue till today. I think it is an issue with your postgres configuration if I read the error properly: no pg_hba.conf entry for host "10.50.50.1", user "prot", database "postgres", SSL off

EuPhobos commented 3 years ago

Sorry, haven't seen your issue till today. I think it is an issue with your postgres configuration if I read the error properly: no pg_hba.conf entry for host "10.50.50.1", user "prot", database "postgres", SSL off

But i do not need database "postgres", i specified the database in the URI as "test" Besides, I have no problems connecting from the same host via the CLI psql -d test -U prot -h 10.50.50.12

sdementen commented 3 years ago

Ok sorry for misunderstanding your issue. Have a look at #91 for the solution

EuPhobos commented 3 years ago

@sdementen yes, in the first post of this issue i say about #91 This solution do not work for me.

sdementen commented 3 years ago

Sorry bis for not reading properly :-( You can pass the argument check_exists=False in open_book as it will skip the test for existence that is causing the root issue

EuPhobos commented 3 years ago

check_exists=False

Oh, thanks! It's work, finally My bad, i missed this solution in #91

sdementen commented 3 years ago

Good! Normally, the bug has to be fixed in the sqlalchemy-utils package so I close your issue