'python running in crontab delivers empty mail

I am running a crontab job on MacOS Catalina. This crontab job runs multiple python scrips for which each job is sending an email. Only the last python script is using Selenium and the job sends an empty email.

The cronjob for this last python script is as follows

58 6 * * * export DISPLAY=:0  &&  cd ~/Documents/Python/cron && /opt/anaconda3/bin/python3 wta.py 2>&1$ | mail -s "Report" [email protected] 

The Python code is as follows:

#!/usr/bin/python3
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
from datetime import datetime
import requests
import mysql.connector
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

s=Service("/usr/local/bin/chromedriver")
chrome_driver='/usr/local/bin/chromedriver'
driver=webdriver.Chrome(service=s)
driver.maximize_window()
driver.get('https://www.wtatennis.com/rankings/singles')
html = driver.page_source
soup = BeautifulSoup(html, features='lxml')

....

val2=[updatetime,'WTA']
query2="""UPDATE Update_date SET Updated = %s WHERE Tablename = %s"""
mycursor.execute(query2,val2)
db.commit()
print(val2)

....

When I run this code in Atom (without the first line) it works perfectly. I searched stackoverflow and other sources but did not find a workable solution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source