当前位置:   article > 正文

Pymysql中插入json内容 dict‘ object has no attribute ‘translate‘_dict' object has no attribute 'translate

dict' object has no attribute 'translate

最近在使用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'
  • 1
  • 2
  • 3

最后发现是单双引号造成的问题,所以我们应该使用以下方法:

aa = pymysql.escape_string(json.dumps({"a": "b", "c": "d"}))
  • 1
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号