我正在尝试使用mysql连接器/python来处理数据库。连接正在成功建立,例如,我能够向表中插入新数据。select查询在处理普通整数或字符值时工作正常。
但是当我尝试执行select查询时,其中一列是int(small、medium、big,无所谓),我遇到了 ValueError: invalid literal for int() with base 0: '00002'
如何重复:
创建一个表,其中 int unsigned zerofill
(或任何其他整数类型) zerofill
). 例如,do CREATE TABLE test_table (id INT UNSIGNED ZEROFILL);
然后 INSERT INTO test_table VALUES (1), (2), (3);
尝试执行游标。使用包含zerofill字段的select查询执行(查询)。 SELECT * FROM test_table;
应该发生什么:程序输出
ValueError: invalid literal for int() with base 0: '0000000001'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\user\Documents\testSQL.py", line 25, in <module>
cursor.execute(query)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\cursor_cext.py", line 272, in execute
self._handle_result(result)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\cursor_cext.py", line 163, in _handle_result
self._handle_resultset()
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\cursor_cext.py", line 651, in _handle_resultset
self._rows = self._cnx.get_rows()[0]
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection_cext.py", line 273, in get_rows
row = self._cmysql.fetch_row()
SystemError: <built-in method fetch_row of _mysql_connector.MySQL object at 0x000002555DDBC350> returned a result with an error set
看起来mysql连接器正在尝试 int(some_number, base=0)
将数据库整数转换为python int()值时。但它实际上是一个以10为基数的数字。我该怎么做才能避免这样的错误呢?
暂无答案!
目前还没有任何答案,快来回答吧!