Python state script gives `exec format error`

I understood that I can write state scripts in python as long as it has the shebang on the top line. So, first question: is that correct?

Mine starts with :


import subprocess
import time
import re
import json
import os
import logging
from contextlib import contextmanager


Unfortunately I’m running into:

`‘’: -1 : fork/exec /var/lib/mender/scripts/

When I execute the script manually by using standalone mender client it works fine. Any ideas? Is the .py ending an issue? Should I have a shell script that call the python script?

Thanks in advance!