Reputation: 183
I'm running a python code, actually the code is running fine, but for some reason, it's printing an error on the screen.
#!/data/go_dl/resources/miniconda3/envs/stg01.nifi_Env/bin/python
import os
import logging
from logging import handlers
landingPath = '/data/go_dl/resources/CMM/'
logPath = '/data/go_dl/resources/CMM/'
logging.basicConfig(filename= logPath+'Log_Rename.log',filemode='w', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(funcName)s => %(message)s')
logging.info("STARTING THE PROCESS")
logging.info("Creating the file with the list of .DAT files to be renamed")
try:
preListFile = []
finalListFile = []
for root, dirs, files in os.walk(landingPath):
for file in files:
if file.endswith('.DAT'):
preListFile.append(landingPath+file)
finalListFile = '\n'.join(sorted(preListFile))
with open("listOfFiles.txt", "w") as f:
f.write(finalListFile)
logging.info("The files to be renamed are :\n"+finalListFile)
except:
logging.error("Error in create the list of .DAT files")
fileList = '/data/go_dl/resources/CMM/listOfFiles.txt'
MST_Prefix = 'NOKIA_CMM_MST_'
ZTN_Prefix = 'NOKIA_CMM_ZTN_'
dateValueList = []
try:
with open(fileList,"r") as arq:
for rowListValue in arq.readlines():
logging.info("rowListValue :",rowListValue)
fileInBytes = open(rowListValue.strip(),'rb')
fileInHexString = fileInBytes.read().hex()
logging.info("Getting the position of the string 9009")
searchedIndexValue = fileInHexString.find('9009')
logging.info("Getting the date value of the file")
fileDateValue = fileInHexString[searchedIndexValue+4:searchedIndexValue+16]
logging.info("The file"+rowListValue+"has the DateValue :"+fileDateValue)
logging.info("Adding 20 to the date value of the value")
dateValueList = "20"+fileInHexString[searchedIndexValue+4:searchedIndexValue+16]
try:
logging.info("renaming the file : "+rowListValue)
#os.rename(rowListValue.strip(), landingPath+MST_Prefix+dateValueList+"_"+rowListValue.strip().split("_")[-1])
except:
logging.error("Error in rename the file"+rowListValue)
except:
logging.error("Error starting the rename of the files")
That's the error appearing on the screen :
--- Logging error --- Traceback (most recent call last): File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 1081, in emit msg = self.format(record) File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 925, in format return fmt.format(record) File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 664, in format record.message = record.getMessage() File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 369, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting Call stack: File "renameFiles_v2.py", line 46, in <module> logging.info("rowListValue :",rowListValue) Message: 'rowListValue :' Arguments: ('/data/go_dl/resources/CMM/NOKIA_CMM_MST_00001.DAT\n',) --- Logging error --- Traceback (most recent call last): File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 1081, in emit msg = self.format(record) File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 925, in format return fmt.format(record) File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 664, in format record.message = record.getMessage() File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 369, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting Call stack: File "renameFiles_v2.py", line 46, in <module> logging.info("rowListValue :",rowListValue) Message: 'rowListValue :' Arguments: ('/data/go_dl/resources/CMM/NOKIA_CMM_MST_00002.DAT\n',) --- Logging error --- Traceback (most recent call last): File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 1081, in emit msg = self.format(record) File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 925, in format return fmt.format(record) File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 664, in format record.message = record.getMessage() File "/data/go_dl/resources/miniconda3/lib/python3.8/logging/__init__.py", line 369, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting Call stack: File "renameFiles_v2.py", line 46, in <module> logging.info("rowListValue :",rowListValue) Message: 'rowListValue :' Arguments: ('/data/go_dl/resources/CMM/NOKIA_CMM_MST_00003.DAT',)
But the log file created by the process is saving the information accordingly.
What am I doing wrong to have the error being printed on the screen?
Upvotes: 0
Views: 3926
Reputation: 183
well, basically what I did to solve the problem was change the line below :
from:
logging.info("rowListValue :",rowListValue)
to:
logging.info("rowListValue :"+rowListValue)
In this part of the code :
try:
with open(fileList,"r") as arq:
for rowListValue in arq.readlines():
logging.info("rowListValue :",rowListValue)
Thanks all
Upvotes: 3