I'm using Python with pandas and xlsxwriter for a automation project in my work, but i need run it as service, for this i using pyinstaller for build an executable file and nssm.exe for install the service. When i use pyinstaller and execute the .exe file before installation of the service, the output files as sucessfull generated. But after service installation and start the following error bellow is returned.
2019-05-16 10:10:30,268 -- GENERIC EXCEPTION: Traceback (most recent call last):
File "service.py", line 75, in main
File "bot.py", line 87, in inicia_consulta
File "bot.py", line 26, in salva_saida
File "site-packages\pandas\io\excel.py", line 1952, in save
File "site-packages\xlsxwriter\workbook.py", line 304, in close
File "site-packages\xlsxwriter\workbook.py", line 652, in _store_workbook
File "zipfile.py", line 1204, in __init__
FileNotFoundError: [Errno 2] No such file or directory: 'H:/DOC/Afogados/Documentos/BotDetran/16-05-2019_1010_PE.xlsx'
I tried various filepath functions but any work for me, also remember that the function normally work when its start without service mode.
This is my function and i detailed it below.
def salva_saida(pd, veiculos):
df = pd.DataFrame(veiculos) # generate dataframe
# capture filedir for the config.yml file
# filedir = 'H:/DOC/Afogados/Documentos/BotDetran/'
filedir = cfg['filedir']
# file = '16-05-2019_1010_PE.xlsx'
file = datetime.now().strftime("%d-%m-%Y_%H%M")+'_PE.xlsx'
# the error ir occurring here
writer = pd.ExcelWriter(filedir+file, engine='xlsxwriter')
...
I tried to assign a user whit access to a H: mapped drive, as BoarGules said, but not work for me. So i solve the problem by creating a link appoint to direct server folder address. Thanks!