Python MySQLdb Insert TypeError:在字符串格式化过程中未转换所有参数

Python MySQLdb Insert TypeError:在字符串格式化过程中未转换所有参数,python,mysql-python,Python,Mysql Python,我正在尝试向数据库中插入一些值 urls =("http://www.**********.net/?page=match") hdr = {'User-Agent': 'Mozilla/5.0'} req = urllib2.Request(urls,headers=hdr) page = urllib2.urlopen(req) soup = BeautifulSoup(page) tournament = soup.find('div',{'class':['content-body']

我正在尝试向数据库中插入一些值

urls =("http://www.**********.net/?page=match")
hdr = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(urls,headers=hdr)
page = urllib2.urlopen(req)
soup = BeautifulSoup(page)

tournament = soup.find('div',{'class':['content-body']})
match_times = tournament.find_all("div", style = "width:10%; float:left;")
match_names = tournament.find_all("div", style = "width:46%; float:left; margin-left:2%; margin-right:2%")
tournys = tournament.find_all("div", style = "width:40%; float:left; overflow:hidden;")


for element in zip(match_times, match_names, tournys):
    results = element[0].text, element[1].text, element[2].text
    matchday=datetime.strptime(results[0], "%d/%m/%y").strftime("%d-%m-%Y")
    info= results[1],results[2],matchday
    conn= MySQLdb.connect(host='localhost',user='root',passwd='',db='sport')
    c = conn.cursor()
    query = "INSERT INTO todaysmatches (match, tournament, matchdate) VALUES (%s,%s,%s)"
    c.executemany(query, info)
    conn.commit()
    conn.close()
    print  info
    print '==================='
match是一个varchar(150),锦标赛varchar(150),matchdate是DATE

这是打印信息的一个示例:

(u'\n\xa0bestest \n9 - 16\ntryPANTS\xa0\n\n', u'\xa0Razer CS:GO Tournament', '08-12-2013')
尝试更改行:

# This expects a list as it's second argument, you are giving it a tuple.
c.executemany(query, info)
为此:

c.executemany(query, [info])

如果这样做有效,那么您可能需要阅读文档,并找出在只需插入一行数据时是否有更好的插入数据的方法。(几乎可以肯定有。)

现在我发现了这个错误编程错误:(1064,“您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解使用“match、Tornament、matchdate”值附近的正确语法\n('\\n\xa0Rasta.eon\\n2-1\\nRasta.Xd\xa0',第1行的'\xa0Ra')尝试
info=results[1] .strip(),results[2].strip(),matchday
并尝试@avoid3d提到的方法将错误更改为值\n('Rasta.eon\\n2-1\\nRasta.Xd','Razer CS:GO'在第1行)编程错误:(1064,“您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册,以了解使用“match,tournamentname,matchdate”值附近的正确语法\n('Rasta.eon 2-1 Rasta.Xd','Razer C'在第1行)相同的错误这是我打印信息时的列表之一[u'Rasta.eon 2-1 Rasta.Xd',u'Razer CS:GO Tournament 2',u'26-02-2014']你能试试
info=str(results[1].strip())、str(results[2].strip())、matchday
c.execute(query,info)
。我想应该能用。