类型错误:无法逃脱psycopg2.extensions.Binary二进制(TypeError:

2019-10-23 02:57发布

我试图通过SQLAlchemy的存储二进制文件到PostgreSQL和文件从客户端上传。 上的错误消息的位谷歌使我此源文件 :“包装对象不是字节或缓冲液,这是一个错误”

   binaries = []
    for f in request.files.values():
        if f and allowed_file(f.filename):
            fn = secure_filename(f.filename)
            file_path = os.path.join(basedir, fn)
            f.save(file_path)
            #data = f.read()
            data = open(fn, 'rb').read()
            binaries.append(psycopg2.Binary(data))
            f.close()
    #does the escaping
    mytable=mytable(
    ...,
    document1 = binaries[0]
    ...
    )
    #Model
    class mytable(mydb.Model):
      document1 = mydb.Column(mydb.LargeBinary())
文章来源: TypeError: can't escape psycopg2.extensions.Binary to binary