首页 > 解决方案 > 防止 mysql.cursor.fetchall() 抛出 ValueError?

问题描述

所以,这是我的代码:

mysql_cur.execute("select * from view_john")
mysql_data = mysql_cur.fetchall()

这是我得到的输出:

ValueError: invalid literal for int() with base 0: '000551'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./xyz.py", line 36, in <module>
    mysql_data = mysql_cur.fetchall()
  File "/home/john/.local/lib/python3.8/site-packages/mysql/connector/cursor_cext.py", line 490, in fetchall
    rows = self._cnx.get_rows()
  File "/home/john/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 318, in get_rows
    else self._cmysql.fetch_row()
SystemError: <method 'fetch_row' of '_mysql_connector.MySQL' objects> returned a result with an error set

我能做些什么来防止这种情况发生?我可以在执行 SELECT 查询时临时更改列类型吗?

标签: pythonmysqlpython-3.xmysql-workbenchmysql-python

解决方案


推荐阅读