Python 2.7.5 を使用しています。すべてのデータベースとテーブルは
私のコードは次のようになります。
import MySQLdb as mdb
import urllib2
import sys
import logging
logging.basicConfig(level=logging.INFO)
from bs4 import BeautifulSoup as BS
con = mdb.connect('loclhost', 'root', '', 'mydb');
cur = con.cursor()
cur.execute('SET NAMES utf8;')
cur.execute('SET CHARACTER SET utf8;')
cur.execute('SET character_set_connection=utf8;')
with con:
...
sql_insert = """INSERT INTO Teams (name, category, countryId) VALUES (%s, 1, %s)"""
cursor = con.cursor()
try:
affected_count = cursor.execute(sql_insert, (name, id)) <<< this line
con.commit()
except mdb.IntegrityError:
logging.warn("failed to insert values %s, %s", name, id)
finally:
cursor.close()
...
con.close()
エラー メッセージの取得:
「UnicodeEncodeError: 'latin-1' コーデックは位置 2 の文字 u'\u015f' をエンコードできません: 序数が範囲内にありません (256)」
上でマークされた行。私は何を間違っていますか?