I use SQLAlchemy and MySQL with the files table to store files. This table is defined as follows:
mysql> show full columns in files; +---------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+ | Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment | +---------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+ | id | varchar(32) | utf8_general_ci | NO | PRI | NULL | | select,insert,update,references | | | created | datetime | NULL | YES | | NULL | | select,insert,update,references | | | updated | datetime | NULL | YES | | NULL | | select,insert,update,references | | | content | mediumblob | NULL | YES | | NULL | | select,insert,update,references | | | name | varchar(500) | utf8_general_ci | YES | | NULL | | select,insert,update,references | | +---------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
A content column of type MEDIUMBLOB is where the files are stored. In SQLAlchemy, this column is declared as:
__maxsize__ = 12582912
I'm not quite sure of the difference between SQLAlchemy BINARY and LargeBinary . Or the difference between MySQL VARBINARY and BLOB . And I'm not quite sure what it matters here.
Question: Whenever I store the actual binary in this table, i.e. Python bytes or b'' , then I get the following warning
.../python3.4/site-packages/sqlalchemy/engine/default.py:451: Warning: Invalid utf8 character string: 'BCB121' cursor.execute(statement, parameters)
I do not want to just ignore the warning, but it seems that the files are in tact. How to handle this warning gracefully, how can I fix its cause?
Lateral note: This question seems to be related, and it seems that this is a MySQL error that is trying to convert all incoming data to UTF-8 ( this answer ).