django项目 MySQLdb.escape_string(json_str) 报错,AttributeError: module ‘pymysql‘ has no attribute ‘escap

import json
import pymysql
import MySQLdb
content = {
     
  "stylers" : {
     
    "color" : "#c4d7f5ff"
  },
  "elementType" : "geometry",
  "featureType" : "water"
}
json_str = json.dumps(content)
print(json_str)
# json字符串不能直接写入到mysql中,需要进行转译

# django项目 MySQLdb.escape_string(json_str) 报错,AttributeError: module 'pymysql' has no attribute 'escape_string'
print(MySQLdb.escape_string(json_str))

# 换成pymysql ,下面可以正常转译
print(pymysql.converters.escape_string(json_str))
# {\"stylers\": {\"color\": \"#c4d7f5ff\"}, \"elementType\": \"geometry\", \"featureType\": \"water\"}

你可能感兴趣的:(Python,python,mysql,json)