Forums

Tasks - PermissionError: [Errno 13] Permission denied

Hi !

Iam trying to run a scheduled task. But I got error as bellow:

The script runs fine at console and in my machine. How can i fix it?

../logs/em_andamento_para_venda_agenciada_2023-08-01-16-33-09-919529.log Traceback (most recent call last): File "/home/mpenner77/praticar_esportes/scripts/em_andamento_para_venda_agenciada.py", line 86, in <module> os.mkdir(pasta_log) PermissionError: [Errno 13] Permission denied: '../logs'

2023-08-01 16:33:10 -- Completed task, took 4.00 seconds, return code was 1.

thank you

Where it's supposed to create the logs directory? Could you try using an absolute path (starting with /) instead?

Hi !

thank you for your reply. Yes, I tried absolute path and it works that way.

that is the location: /home/mpenner77/praticar_esportes/logs

is there anyway to use relative path ?

tks

Sure. Just make sure that you understand where the working directory is, then you can use path relative to that.

Hi !

i have tried the follow code, but still got the same error. it just working when I hardcode the absolute path, any tips?

pasta_relativa = '../logs'

pasta_log = os.path.abspath(pasta_relativa)

caminho_completo_arquivo_log = os.path.join(pasta_log,nome_arquivo_log)+ current_datetime.strftime("%Y-%m-%d-%H-%M-%S-%f") + ".log"

def cria_pasta_log(pasta_log, caminho_completo_arquivo_log):

if not os.path.exists(pasta_log):
    os.mkdir(pasta_log)

if not os.path.exists(caminho_completo_arquivo_log):
    with open (caminho_completo_arquivo_log, "x"):
        pass

Traceback (most recent call last): File "/home/mpenner77/praticar_esportes/scripts/check_out_atendido.py", line 290, in <module> cria_pasta_log(pasta_log, caminho_completo_arquivo_log) File "/home/mpenner77/praticar_esportes/scripts/check_out_atendido.py", line 77, in cria_pasta_log os.mkdir(pasta_log) PermissionError: [Errno 13] Permission denied: '/home/logs'

2023-08-03 18:54:13 -- Completed task, took 6.01 seconds, return code was 1.

Looks like you're trying to create a directory in the /home directory where you don't have permissions to do so. You can get your HOME dir (/home/mpenner77) by using os.path.expanduser('~') for example, if you don't want to hard code it, and then use paths relative to it, since you have permissions to write there.