1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
606 stars 201 forks source link

TypeError: function takes at most 3 arguments (4 given) #291

Closed tomjeannesson closed 1 year ago

tomjeannesson commented 1 year ago

Hello, I get the following error when executing db = Db(db_uri=db_uri, password=password).

  File "/app/napsedjango/_bitcoin/bitcoin_wallet_manager.py", line 64, in __init__
    db = Db(db_uri=db_uri, password=password)
  File "/usr/local/lib/python3.10/site-packages/bitcoinlib/db.py", line 70, in __init__
    Base.metadata.create_all(self.engine)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 5581, in create_all
    bind._run_ddl_visitor(
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3225, in _run_ddl_visitor
    with self.begin() as conn:
  File "/usr/local/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3215, in begin
    with self.connect() as conn:
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3251, in connect
    return self._connection_cls(self)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 145, in __init__
    self._dbapi_connection = engine.raw_connection()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3275, in raw_connection
    return self.pool.connect()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 420, in connect
    return _ConnectionFairy._checkout(self, self._fairy)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1271, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 719, in checkout
    rec = pool._do_get()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/impl.py", line 402, in _do_get
    c = self._create_connection()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 396, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 681, in __init__
    self.__connect()
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 919, in __connect
    )._exec_w_sync_on_first_run(self.dbapi_connection, self)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/event/attr.py", line 473, in _exec_w_sync_on_first_run
    self(*args, **kw)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/event/attr.py", line 487, in __call__
    fn(*args, **kw)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 714, in on_connect
    do_on_connect(dbapi_connection)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/dialects/sqlite/pysqlcipher.py", line 145, in on_connect
    super_on_connect(conn)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 574, in connect
    fn(conn)
  File "/usr/local/lib/python3.10/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 557, in set_regexp
    dbapi_connection.create_function(
TypeError: function takes at most 3 arguments (4 given)

I am using:

bitcoinlib==0.6.9 # https://github.com/1200wd/bitcoinlib
pysqlcipher3==1.2.0 # https://github.com/sqlcipher/sqlcipher
SQLAlchemy==2.0.7

Works fine with SQLAlchemy==1.4.46. Any ideas?

mccwdev commented 1 year ago

It seems the latest version of SQLAlchemy is not compatible with pysqlcipher3 and/or sqlite3 anymore. The issue seems related to this https://github.com/sqlalchemy/sqlalchemy/discussions/9379

For now downgrading to an older version of SQLAlchemy fixes the issue. Or using the patch mentioned in the previous thread, but I didn't test this.

tomjeannesson commented 1 year ago

Ok thanks, I'll just stick with SQLAlchemy < 2.0.0 for now.

mccwdev commented 1 year ago

With this library https://github.com/coleifer/sqlcipher3 it seems to work with the SQLAlchemy 2.0.9

mccwdev commented 1 year ago

Updated instructions in documentation