我正在开发从 Instagram 到 Telegram 机器人的集成,它将监控用户帐户和每个新帖子,我都会在 Telegram 上收到通知。我正在为这个项目创建表,并坚持使用 SQLAlchemy 创建表,有人已经遇到过这些问题吗?
from sqlalchemy import Column, Integer, DateTime, Text, Boolean
from config import Base, engine
import uuid
class InstagramImageNoRss(Base):
__tablename__ = 'instagram_image_norss'
__table_args__ = {'sqlite_autoincrement': True}
id = Column(Text, primary_key=True, default=lambda: uuid.uuid4().hex)
local_path = Column(Text)
local_path_txt = Column(Text)
local_path_json = Column(Text)
comments_path = Column(Text)
geolocation_path = Column(Text)
text_data = Column(Text)
json_data = Column(Text)
comments_data = Column(Text)
geolocation_data = Column(Text)
username = Column(Text)
sended = Column(Boolean)
published = Column(DateTime)
publication_index = Column(Integer)
def __str__(self):
import json
return json.dumps(self.__dict__, default=str)
class InstgaramImageRss(Base):
__tablename__ = 'instagram_image_rss'
__table_args__ = {'sqlite_autoincrement': True}
id = Column(Text, primary_key=True, default=lambda: uuid.uuid4().hex)
published = Column(DateTime)
local_name = Column(Text)
local_path = Column(Text)
rss_webstagram_id = Column(Text)
summary = Column(Text)
media_url = Column(Text)
image_hash = Column(Text)
creation_time = Column(DateTime)
link = Column(Text)
sended = Column(Boolean)
username = Column(Text)
def __str__(self):
import json
return json.dumps(self.__dict__, default=str)
class InstagramSubscription(Base):
__tablename__ = 'instagram_subscription'
__table_args__ = {'sqlite_autoincrement': True}
id = Column(Text, primary_key=True, default=lambda: uuid.uuid4().hex)
username = Column(Text, primary_key=True, unique=True)
last_check_datetime = Column(DateTime)
subscribed = Column(Boolean)
def __str__(self):
import json
return json.dumps(self.__dict__, default=str, indent=4)
class Chat(Base):
__tablename__ = 'chats'
__table_args__ = {'sqlite_autoincrement': True}
id = Column(Text, primary_key=True, default=lambda: uuid.uuid4().hex)
chat_id = Column(Integer)
admin = Column(Boolean)
tg_ans = Column(Text)
def __str__(self):
import json
return json.dumps(self.__dict__, default=str, indent=4)
# Error happens here
Base.metadata.create_all(engine)
我收到以下错误:TypeError:函数最多需要 3 个参数(给定 4 个)
当前使用 SQLite3 3.37.2 和 PY 3.11.1
按照要求,完全回溯错误:
File "/workspace/InstagramTelegramBot/InstagramBotDAO.py", line 76, in <module>
Base.metadata.create_all(engine)
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/sql/schema.py", line 5828, in create_all
bind._run_ddl_visitor(
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 3242, in _run_ddl_visitor
with self.begin() as conn:
File "/home/ribeiroo/.pyenv/versions/3.11.1/lib/python3.11/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 3232, in begin
with self.connect() as conn:
^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 3268, in connect
return self._connection_cls(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 145, in __init__
self._dbapi_connection = engine.raw_connection()
^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 3292, in raw_connection
return self.pool.connect()
^^^^^^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/pool/impl.py", line 421, in connect
return _ConnectionFairy._checkout(self, self._fairy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 1269, in _checkout
fairy = _ConnectionRecord.checkout(pool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 716, in checkout
rec = pool._do_get()
^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/pool/impl.py", line 403, in _do_get
c = self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 393, in _create_connection
return _ConnectionRecord(self)
^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 678, in __init__
self.__connect()
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 916, in __connect
)._exec_w_sync_on_first_run(self.dbapi_connection, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/event/attr.py", line 473, in _exec_w_sync_on_first_run
self(*args, **kw)
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/event/attr.py", line 487, in __call__
fn(*args, **kw)
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 704, in on_connect
do_on_connect(dbapi_connection)
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/sqlite/pysqlcipher.py", line 145, in on_connect
super_on_connect(conn)
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/sqlite/pysqlite.py", line 574, in connect
fn(conn)
File "/workspace/InstagramTelegramBot/.venv/lib/python3.11/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)
我可以通过安装 pysqlcipher 并创建这样的引擎来重现此错误:
create_engine('sqlite+pysqlcipher://:password@/so77320976.db'
如果我安装 sqlcipher3 驱动程序,则不会出现该错误。