Hello ,
I have a small app that uplaod file to my devices using FTP and update the DB.
it's working
my question is - is the "Exceptions" part good? meaning , how do I know if there are other "problems"? also do I need to use "except" and also "Exception as e"?
or both of them point at the same problem ?
I have a small app that uplaod file to my devices using FTP and update the DB.
it's working
my question is - is the "Exceptions" part good? meaning , how do I know if there are other "problems"? also do I need to use "except" and also "Exception as e"?
or both of them point at the same problem ?
try:
for file in Files_Path:
Upload_Status = 'unknown'
Upload_Status = upload_script(Unit_IP, file)
except (ConnectionError, TimeoutError):
print('TimeOut error - Unit is offline maybe?')
Upload_Status = 'Offline'
except Exception as e:
print(e)
print('\x1b[3;30;41m' + f'Error! {Unit_IP}' + '\x1b[0m')
Notupload += 1
NotUploadIpList.append(Unit_IP)
Upload_Status = 'Error'
except:
print(e)
print('Unknown error!!!!!! ' + Unit_IP)
Upload_Status = 'Unknown Error'
else:
print('\x1b[6;30;42m' + f'Success! {Unit_IP}' + '\x1b[0m') ## no problem detected
Upload += 1
finally:
mycursor1 = mydb.cursor()
sql1 = f"update david.david_test set COMMENT = '" + Upload_Status + "',SendTime=NOW() where Unit_ip = '" + Unit_IP + "';"
mycursor1.execute(sql1)
mydb.commit()Thanks ,
