特殊字符问题python前夕

时间:2019-06-07 08:18:25

标签: python sqlalchemy collation pymysql eve

我使用python eve框架作为后端从数据库中获取数据。但是,其中一个表中的一列具有特殊字符。错误显示为:

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1267, "Illegal mix of collations (latin1_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'")
[SQL: SELECT count(*) AS count_1 
FROM (SELECT table._created AS 
table__created, table._updated AS 
table__updated, table._etag AS 
table__etag, table.created_at AS 
table_created_at, table.updated_at AS 
table_updated_at, table.id AS 
table_id, table.name AS 
table_name, table.instructions AS 
table_instructions, table.updated_by AS 
table_updated_by 
FROM table 
WHERE table.name LIKE %(name_1)s ORDER BY 
table.id DESC) AS anon_1]
[parameters: {'name_1': '�%'}]
(Background on this error at: http://sqlalche.me/e/2j85)

顺便说一下,API就像这样:

https://api.prod.com/table?where={%22name%22:%22like(\%22%Aa%\%22)%22}&sort=-id
  1. 我们尝试的第一个解决方案是更改表中列的排序规则。它没用。
  2. 接下来,我运行一个脚本以将每行的所有字符更新为ASCII。因此,以下代码在循环中转换了每一行“名称”。

    name=""
    if(rec['name']):
       for ch in rec['name']:
           name+=chr(ord(ch))
    

他们两个都不起作用。

如何使它工作?任何帮助表示赞赏。

0 个答案:

没有答案