Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
development:python [2023/09/19 13:38] – [Execute Bash command and capture output] Zyzonixdevelopment:python [2024/02/27 07:32] (current) Zyzonix
Line 52: Line 52:
         return mailText         return mailText
  
-    def sendMail(self, hosts, awakeList, failedList, statusUnknownList):+    def sendMail(self):
         if EMAILRECEIVER and EMAILSENDER and MAILSERVER and MAILSERVERPORT:         if EMAILRECEIVER and EMAILSENDER and MAILSERVER and MAILSERVERPORT:
             import smtplib             import smtplib
Line 65: Line 65:
             msgRoot = MIMEMultipart("alternative")             msgRoot = MIMEMultipart("alternative")
             msgRoot['Subject'] = Header(subject, "utf-8")             msgRoot['Subject'] = Header(subject, "utf-8")
-            msgRoot['From'] = "wolserver <" + EMAILSENDER + ">"+            msgRoot['From'] = "Python-Script <" + EMAILSENDER + ">"
             msgRoot['To'] = EMAILRECEIVER             msgRoot['To'] = EMAILRECEIVER
-            mailContent = MIMEText(wakeup.buildMail(self))+            mailContent = MIMEText(buildMail(self))
             mailText = MIMEText(mailContent, "plain", "utf-8")             mailText = MIMEText(mailContent, "plain", "utf-8")
             msgRoot.attach(mailText)             msgRoot.attach(mailText)
Line 119: Line 119:
                          
                          
-            mailContent = wakeup.buildMail(self)+            mailContent = buildMail(self)
             mailText = MIMEText(mailContent, "plain", "utf-8")             mailText = MIMEText(mailContent, "plain", "utf-8")
                          
Line 127: Line 127:
                                  
             except:             except:
-                logging.writeError(self, "Failed to send mail to " + EMAILRECEIVER + " | Check your settings!"+                print(self, "Failed to send mail to " + EMAILRECEIVER + " | Check your settings!"
-                logging.writeExecError(self, traceback.format_exc())+                print(self, traceback.format_exc())
                          
         else:         else:
-            logging.write(self, "Mailing disabled or not configured properly.")+            print(self, "Mailing disabled or not configured properly.")
 </code> </code>
 ++++ ++++
Line 157: Line 157:
 ++++ ++++
 </panel> </panel>
 +
 +==== FastAPI/Uvicorn ====
 +=== Change Log Format ===
 +Adding the following lines to your ''uvicorn'' initialization function will change the output of the webserver:
 +<code bash>
 +log_config = uvicorn.config.LOGGING_CONFIG
 +log_config["formatters"]["access"]["fmt"] = "%(asctime)s - %(levelname)s - %(message)s"
 +uvicorn.run(app, port=80, host=SERVERIP, log_config=log_config)
 +</code>
 +
 +//Sourced from [[https://github.com/tiangolo/fastapi/issues/1508|github.com - tiangolo/fastapi]]//
  • development/python.1695123497.txt.gz
  • Last modified: 2023/09/19 13:38
  • by Zyzonix