Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql和python的编码问题_Python_Mysql - Fatal编程技术网

mysql和python的编码问题

mysql和python的编码问题,python,mysql,Python,Mysql,我有python代码,可以从更大的学校提取数据并将其存储在我们的服务器上。一切都很好,直到它击中角色。我将数据库编码为UTF-8 general,代码将上述字符存储为:xc1 import schoolslib, MySQLdb cities = schoolslib.getcitylist("ca") for city in cities: schools = schoolslib.getschoolstest(city) data = ['gsId', 'name', 'type', '

我有python代码,可以从更大的学校提取数据并将其存储在我们的服务器上。一切都很好,直到它击中角色。我将数据库编码为UTF-8 general,代码将上述字符存储为:xc1

import schoolslib, MySQLdb

cities = schoolslib.getcitylist("ca")

for city in cities:
schools = schoolslib.getschoolstest(city)
data = ['gsId', 'name', 'type', 'gradeRange', 'enrollment', 'gsRating', 'parentRating', 'city', 'state', 'districtId', 'district', 'districtNCESId', 'address', 'phone', 'fax', 'website', 'ncesId', 'lat', 'lon', 'overviewLink', 'ratingsLink', 'reviewsLink', 'schoolStatsLink']
db = MySQLdb.connect(host="localhost", user="schools", passwd="", db="schoolinfo")
cursor = db.cursor()
schooldata = [0]*23
for school in schools.iter('school'):
    for x in range(0, 23):
        schooldata[x] = school.find(data[x])
        if (schooldata[x] == None) or (schooldata[x].text == None) :
            schooldata[x] = ""
        else:
            schooldata[x] = schooldata[x].text
            schooldata[x] = schooldata[x].encode('utf-8', "ignore")

    cursor.execute("INSERT INTO school (gsId,name,type,gradeRange,enrollment,gsRating,parentRating,city,state,districtId,district,districtNCESId,address,phone,fax,website,ncesId,lat,lon,overviewLink,ratingsLink,reviewsLink,schoolStatsLink) VALUES %r;" % (tuple(schooldata),))
db.commit()
XML文件:
Ánimo Inglewood Charter High School

连接数据库时,分配字符集,并在建立MySQL连接时使用_unicode参数

db = MySQLdb.connect(host="localhost", 
                     user="schools", 
                     passwd="", 
                     db="schoolinfo",
                     charset = "utf8",
                     use_unicode =True)

它仍然在显示xc3x81nimo,而Ánimo应该在哪里