I ran the script as cron. Is it possible to run this with sudo?
You can put python script.pyin a cron a user with sufficient rights (for example, root or a user with permissions on files and devices)
I don’t know which OS you are using, but if Raspbian is close to Debian, there is no need for sudo or root, just use a user with sufficient permissions.
I think I can do it too check_output check_output(["sudo", "/home/pi/bin/lol_dht22/loldht", "7"], timeout=10)
Of course, but the unix user that will reference this Python script will need the sudo privilege (otherwise it cannot call sudofrom subprocess). In this case, you can also do as described above, run cron from the user with the necessary permissions.
source
share