Single

解决Python出现TypeError: coercing to Unicode: need string or buffer, int found错误

造成错误产生的原因为拼接字符串时出现了int类型的数据,原数据为:

sql = u"update all_link set post_page=" + pdf_meta['page'] + ", link_content_length=" + pdf_meta['size'] + ", post_title = '" + MySQLdb.escape_string(pdf_meta['title']) +"', post_author='"+ MySQLdb.escape_string(pdf_meta['author']) +"', post_subject='" +MySQLdb.escape_string(pdf_meta['subject']) + "' where link_slug = '"+ post[1]+"'"

解决方法,将拼接字符串时出现的int类型变量使用str方法转换为字符串,故修改为:

sql = u"update all_link set post_page=" + str(pdf_meta['page']) + ", link_content_length=" + str(pdf_meta['size']) + ", post_title = '" + MySQLdb.escape_string(pdf_meta['title']) +"', post_author='"+ MySQLdb.escape_string(pdf_meta['author']) +"', post_subject='" +MySQLdb.escape_string(pdf_meta['subject']) + "' where link_slug = '"+ post[1]+"'"

暂无评论

发表评论