CRON: Pyscreenshot all backends failed
Posted: Wed Jul 15, 2020 6:49 pm
Dear Community
I am trying to get a program from Vitor (https://stackoverflow.com/questions/578 ... attachment) to run every 15 minutes with crontab. The script works fine if I run it from the terminal with the following command
I then tried to get it to run with cron, but it simply didn't work. I made sure that cron works (and it does when using other scripts) and have used this troubleshooting guide (https://garyhall.org.uk/troubleshooting ... ry-pi.html). I got to point three and there I found the problem, however, I cannot solve it. Point three suggests to try if the "very limited" cron environment can run the job by running the following command:
This command leads me to the bash-5.0$. If I then run the first mentioned command (running the script) in bash-5.0$, then I get the following error:
This is the python code which I am using (and which works if run from terminal with sudo priveliges):
Since all permissions are correct and the script runs from terminal, there is definitely something wrong with cron which needs to be adjusted. Any ideas are welcome.
Best regards
I am trying to get a program from Vitor (https://stackoverflow.com/questions/578 ... attachment) to run every 15 minutes with crontab. The script works fine if I run it from the terminal with the following command
Code: Select all
sudo python /home/<username>/somepath/webscreen.py Code: Select all
env -i /bin/bash --noprofile --norcCode: Select all
bash-5.0$ sudo python /home/<username>/somepath/webscreen.py
Traceback (most recent call last):
File "/home/<username>/somepath/webscreen.py", line 44, in <module>
main()
File "/home/<username>/somepath/webscreen.py", line 39, in main
imagem = ImageGrab.grab()
File "/usr/local/lib/python2.7/dist-packages/pyscreenshot/__init__.py", line 31, in grab
return backend_grab(backend, bbox, childprocess)
File "/usr/local/lib/python2.7/dist-packages/pyscreenshot/loader.py", line 147, in backend_grab
return auto(bbox, childprocess)
File "/usr/local/lib/python2.7/dist-packages/pyscreenshot/loader.py", line 127, in auto
raise FailedBackendError(msg)
pyscreenshot.err.FailedBackendError: All backends failed!Code: Select all
import smtplib
#from PIL import ImageGrab (does not work since only for mac / windows)
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
import os.path
import pyscreenshot as ImageGrab
def enviar_email():
email = 'Someemail'
password = 'Somepassword'
subject = 'Info'
message = 'Created by Vitor, edited by Marco'
file_location = 'Some.jpg'
msg = MIMEMultipart()
msg['From'] = email
msg['To'] = 'Someotheremail'
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
# Setup the attachment
filename = os.path.basename(file_location)
attachment = open(file_location, "rb").read()
image = MIMEImage(attachment, name=filename)
msg.attach(image)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, email, text)
server.quit()
def main():
imagem = ImageGrab.grab()
imagem.save('Stats.jpg', 'jpeg')
enviar_email()
if __name__ == '__main__':
main()Best regards