我在mysql数据库中填充一个表。有很多行(比如100万行)。我成功运行了代码,它用所有行填充数据库。但最后我得到了以下警告(多次),表明存在一些编码问题。所以我使用charset = 'utf8'
并使用str.encode('utf8')
作为我认为可能存在此类错误的字符串。
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xC5\\xABmo 5...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90mul...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90ate...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90rah...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90num...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90puk...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90lom...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90ruu...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90poi...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90WC-...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xE2\\x80\\x90ham...' for column 'productname' at row 1")
result = self._query(query)
/usr/lib/python3/dist-packages/pymysql/cursors.py:167: Warning: (1366, "Incorrect string value: '\\xC5\\xABmo 5...' for column 'productname' at row 1")
result = self._query(query)
代码文件足够大但我可以把我的代码与上述问题相关联:
try: data = (productid_i, time_i, store_i, name_i, price_i, category_i, url_i, year_i, week_i)
except ValueError as e: print(e)
try: self.cursor.execute('INSERT INTO productinfo (productid, scrappingdate, storeid, productname, price, categoryid, url, annual, week )' 'VALUES("%s", date(%s), "%s", "%s", "%s", "%s", "%s", "%s", "%s" )', data)
except ValueError as e: print(e)
因为有这么多行我无法检查它对我的字符串的影响。有人可以指导我这个警告是否真的会影响字符串以及解决这个问题的方法是什么?感谢