1
I’m developing a client
that le files .JSON
and sends them to an API. Files are deposited periodically in a folder. However, what I want is that when an error occurs with the file (file being used, file with syntax error, etc.) that file is moved to another folder and the client
ignore this file and continue reading the others. How can I do?
Follow me code so far:
for file in glob.glob(diretorioIn +'*.json'):
print("Iniciando Leitura")
try:
payload = json.load(open(file))
print(file)
print(payload)
print(file)
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
url = 'http://10.24.1.71/track/add'
result = requests.post(url, data=json.dumps(payload), headers=headers)
print(result.text)
os.remove(file)
except ValueError:
print("Arquivo com erro: ")
print(file)
os.rename(file, diretorioErro)
except PermissionError:
print("Arquivo está sendo usado. Será movido para a pasta ERROR")
print(file)
os.rename(file, diretorioErro)
print("Nenhum arquivo encontrado. Reprocessando WebService")