最近在使用pymysql插入数据时,会出现以下报错
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'det":
和
dict' object has no attribute 'translate'
最后发现是单双引号造成的问题,所以我们应该使用以下方法:
aa = pymysql.escape_string(json.dumps({"a": "b", "c": "d"}))