Forums

File doesn’t found

Hi, When I’m using always-on-task with my script.py which need to call another script, I got this in logs

2023-08-01 21:17:43 - Task preparing to start Aug 1 21:18:55 config/template_config.toml does not exist!

Here my script.py

if not os.path.isfile("config/template_config.toml"): log.fatal("config/template_config.toml does not exist!") exit(254)

Try using absolute paths instead of relative ones.

But from where? do I need to start from home/ or my site/? Do I need to change the previous code if I change the type a path (relative to absolute)?

Because I tried /home/myname/mysite/config/template_config.toml home/myname/mysite/config/template_config.toml

The absolute path would be /home/LouisBluteau/mysite/config/template_config.toml

That’s exactly what I did but files doesn’t found again…

if not os.path.isfile("/home/LouisBluteau/my site/config/template_config.toml"): log.fatal("template_config.toml does not exist!") exit(254)

It looks like you have an extra space in there, in between "my" and "site".

even without space... I dunno what I can do and I need to fix it fast

Did you reload the web app after making changes in the code?

Yes, I saved then reloaded

When I run the code manually it’s work even with the absolute path

I'd confirm in the bash console that your file path exists, eg ls -la /home/LouisBluteau/my_site/config/template_config.toml

enter image description here

https://ibb.co/86CGgKK

When I use Bash console to confirm I find this path: /home/LouisBluteau/mysite/config/template_config.toml

That's strange... could you share your code again?

enter image description here

https://ibb.co/c2D3QfD

When I run the code manually my path is : config/template_config.toml and it’s works

Sorry, I missed the fact that you're running it as an Always-on task, not in a web app, in my reply above! Could you check if the always on task is still running and what are the most recent logs in the task's log?

The always on task stays in « Starting » and the most recent logs is :

Aug 9 09:59:34 config/template_config.toml does not exist!

UPDATE: I can manually run the code with the long path (below) but not working always with always on task.

/home/LouisBluteau/mysite/config/template_config.toml

Yes, in an always-on task it's best to either explicitly set the working directory at the start of the command using cd, or to use an absolute path rather than a relative one.

Could you give some more details about what you mean when you say that it's not working always?

I was wrong, I meant it’s not working at all when I use Always task on.

But I am already using absolute path by starting from /home/ ? Do I need to change my code ?

If you're already using an absolute path, you should be fine. Can we take a look at your files? We can see them from our admin interface, but we always ask for permission first.

Yes of course you can. The script that I try to run on always task on is Core.py. Thanks you

It looks like you've made one reference to the file (at line 34) absolute, but there are a number of other references that are still relative. Try fixing those as well, and see if that helps.

I changed all references to absolute but same error in logs. You can check changes.

UPDATE (Resolved) : Core.py need imports which call others fils so I needed to change paths in others files before

Glad to hear that you made it work!