Forums

Strange behavior

Hello, I have this script:

message = f"From: {FROM}\nTo: {TO}\nSubject: {OGGETTO}\n\n{TEXT}"

in a file that starts every day in a scheduled task and it gives this error:

"File "/home/vittus/mysite/segnala_allerte.py", line 65 message = f"From: {FROM}\nTo: {TO}\nSubject: {OGGETTO}\n\n{TEXT}" ^ SyntaxError: invalid syntax"

but if I run it manually it works fine!!

I don't understand where is the mistake!

Thank you!

What python version do you run it with?

There are multiple versions of Python installed; if you run "python3.8", you'll get Python 3.8, if you run "python3.7", you'll get 3.7, and so on. They all have their own associated versions of pip installed, eg. "pip3.8".

I did install requirements.txt from the bash console with pip3.8, but it gives me the same error. Manually keeps working! :(

Are you sure that you're using Python 3.8 for the scheduled task? If you just schedule something like this:

/home/vittus/mysite/segnala_allerte.py

...then our system will have to guess which Python version you want to run it with, and might guess wrong. If, instead, you schedule this:

python3.8 /home/vittus/mysite/segnala_allerte.py

...then it will always be run with Python 3.8.

Yes, you're right! Thank you!!

No problem, glad to help :-)