Forums

Dict merge Syntax Error while running scheduled task

I have a small piece of code that I've set up to run as a scheduled task once a day. I've tested this code locally and it works fine. My local Python version is 3.8+ for better context. This is the callback in the task logs.

with requests.get(urlbase, {**params, 'storeid': id['class'][1].split('_')[1]}) as resp:
                             ^
SyntaxError: invalid syntax

Now I'm not sure exactly why this would raise a syntax error except that perhaps the task environment is not actually running Python 3.8 as it should. I don't quite remember when ** dict merging was added to Python but I'm pretty sure it's been around in Python 3 for a while.

Is there a way to verify what Python version the scheduled task runs on? If it is running on something <3.8 (or even 2.x) is there a way to force it to use a 3.8 environment?

You can put a full Bash command into the "Command" field for a scheduled task, so you can specify the version of Python there. Right now you have something like this:

/home/TheArtificiallylntelligent/something/somethingelse.py

(I've not posted the exact command just in case there's some private information there), so you can make sure that it's run with Python 3.8 by changing it to this:

python3.8 /home/TheArtificiallylntelligent/something/somethingelse.py

Ahh, thanks giles. I'll try this!

Great! Let us know if you have any problems.

Altering the Command field did allow the task to run but now I get the 403 error indicative of the target website not being whitelisted. I don't think it has a public API either (MicroCenter).

If it doesn't have a public API, we're not going to whitelist it. If you want to get data by scraping, you need a paid account.