我有代码,它使用python将excel中的数据插入到mysql中。
我试图捕捉到一些错误信息,并向最终用户显示更清楚的信息,例如:
如果您试图将NaN插入mysql,系统将显示以下信息:
‘1054 (42S22):“字段列表”中未知列'nan’
如何捕捉此错误消息以显示更清楚的信息,如:
if ErrorCode='1054':
print('please check at original file at see whether there is empty value at certain area"我使用
try:
except Exception as:
print(e)以捕获错误消息,但这不能显示显式信息。
我可能错了,请尽管说吧。
谢谢。
发布于 2020-06-27 12:59:21
这是相当直截了当的战争见手册
except mysql.connector.Error as err:
if err.errno == 1054:
print("please check at original file at see whether there is empty value at certain area")
else:
print("Another error")https://stackoverflow.com/questions/62610205
复制相似问题