首页 > 解决方案 > 并非所有参数都在字符串格式化期间转换(Flask、ImageMagick 和 SQLAlchemy_ImageAttach)

问题描述

我真的无法理解这个错误。当我尝试对 user.picture 进行更改时,它会发送写在标题中的错误。我无法找到任何其他与此相关的错误发生的示例。

这是错误:

not all arguments converted during string formatting on line 429

第 429 行如下所示:

db.session.commit()

这是我的商店:

store = FileSystemStore(
    path='bin/static/img',
    base_url='/'
)

如果我改用这样的商店,我会得到同样的错误:

store = HttpExposedFileSystemStore(
    path='bin/static/img/',
    prefix='static/img/'
)

这是我尝试提交给定图片的示例

with store_context(main.AppClass.store):
    current_user.picture.from_file(_profile_picture)
    db.session.commit()

这是我尝试对二进制执行相同操作的示例

with store_context(main.AppClass.store):
    byte_str = base64.b64encode(_profile_picture.read())
    decoded_byte_str = base64.b64decode(byte_str)
    current_user.picture.from_blob(decoded_byte_str)
    db.session.commit()

他们都给了我同样的错误,这让我相信我的商店可能有问题,但我无法真正开始理解如何。

但是,如果我做这样的事情作为测试,看看它是否有效:

  with store_context(main.AppClass.store):
      current_user.set_name("asd")
      db.session.commit()

它毫无问题地提交。我在这里有点不知所措,不胜感激。

标签: pythonflasksqlalchemyimagemagickwand

解决方案


推荐阅读