簡體   English   中英

如何修改 Crontab 郵件 Output?

[英]How to modify the Crontab Mail Output?

目前,我收到 email 的 crontab 異常的 output:

Traceback (most recent call last):
  File "test.py", line 137, in test
    self.product_to_cart()
  File "test.py", line 18, in product_to_cart
    atc_btn = self.driver.find_element_by_id('product-addtocart-button')
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 360, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
    'value': value})['value']
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="product-addtocart-button"]"}
  (Session info: headless chrome=77.0.3865.90)

是否可以修改 output 以便不使用 selenium 的人在收到這種 crontab 郵件 Z78E6221F6393D1356681DB398F14CE6D 時知道發生了什么? 像一些更具人類可讀性的 output..

我已經嘗試使用普通打印並引發異常(消息),但它沒有出現在 email

注意:這不是解決錯誤消息本身..只是輸出的可視化(!)

謝謝!

這不是“crontab 異常”,而是 cron 剛剛傳遞的 Python 異常。 Cron 只是將腳本的 output 發送給您。 腳本的 output 是未捕獲的異常消息。 捕獲異常並打印您希望郵件說的內容。

try:
    do_something_dangerous()
except selenium.common.exceptions.NoSuchElementException as x:
    print("Bad stuff happened!", file=sys.stderr)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM