{"id":54853,"date":"2025-08-13T12:10:04","date_gmt":"2025-08-13T04:10:04","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/54853.html"},"modified":"2025-08-13T12:10:04","modified_gmt":"2025-08-13T04:10:04","slug":"%e8%bf%9b%e9%98%b6%e5%90%91python%e7%bc%96%e5%86%99%e8%87%aa%e5%8a%a8%e5%8c%96%e9%82%ae%e4%bb%b6%e5%8f%91%e9%80%81%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/54853.html","title":{"rendered":"\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f"},"content":{"rendered":"<h4>Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f&#xff1a;\u4ece\u96f6\u5f00\u59cb\u8be6\u89e3<\/h4>\n<p>\u5728\u6570\u5b57\u5316\u65f6\u4ee3&#xff0c;\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u529f\u80fd\u5df2\u6210\u4e3a\u4f01\u4e1a\u548c\u4e2a\u4eba\u63d0\u5347\u5de5\u4f5c\u6548\u7387\u7684\u91cd\u8981\u5de5\u5177\u3002\u636e\u7edf\u8ba1&#xff0c;\u5168\u7403\u6bcf\u5929\u53d1\u9001\u7684\u5546\u4e1a\u90ae\u4ef6\u8d85\u8fc730\u4ebf\u5c01&#xff0c;\u5176\u4e2d\u7ea640%\u662f\u901a\u8fc7\u81ea\u52a8\u5316\u7cfb\u7edf\u53d1\u9001\u7684\u3002\u8fd9\u79cd\u529f\u80fd\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8e\u591a\u79cd\u573a\u666f&#xff1a;\u5728\u65e5\u5e38\u529e\u516c\u4e2d\u7528\u4e8e\u81ea\u52a8\u53d1\u9001\u4f1a\u8bae\u901a\u77e5\u548c\u65e5\u7a0b\u63d0\u9192&#xff1b;\u5728\u7535\u5546\u9886\u57df\u7528\u4e8e\u8ba2\u5355\u786e\u8ba4\u548c\u7269\u6d41\u8ddf\u8e2a&#xff1b;\u5728\u8425\u9500\u63a8\u5e7f\u4e2d\u7528\u4e8eEDM\u90ae\u4ef6\u8425\u9500\u548c\u5ba2\u6237\u5173\u6000&#xff1b;\u5728IT\u7cfb\u7edf\u4e2d\u7528\u4e8e\u53d1\u9001\u544a\u8b66\u901a\u77e5\u548c\u9a8c\u8bc1\u7801\u7b49\u3002<\/p>\n<p>Python\u51ed\u501f\u5176\u7b80\u6d01\u4f18\u96c5\u7684\u8bed\u6cd5\u548c\u5f3a\u5927\u7684\u751f\u6001\u7cfb\u7edf&#xff0c;\u6210\u4e3a\u5b9e\u73b0\u90ae\u4ef6\u81ea\u52a8\u5316\u7684\u9996\u9009\u7f16\u7a0b\u8bed\u8a00\u3002\u5176\u6807\u51c6\u5e93\u4e2d\u7684smtplib\u548cemail\u6a21\u5757\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u90ae\u4ef6\u5904\u7406\u529f\u80fd&#xff0c;\u800c\u7b2c\u4e09\u65b9\u5e93\u5982yagmail\u66f4\u662f\u5c06\u53d1\u9001\u8fc7\u7a0b\u7b80\u5316\u5230\u6781\u81f4\u3002Python\u7684\u8de8\u5e73\u53f0\u7279\u6027\u4f7f\u5176\u53ef\u4ee5\u5728Windows\u3001Linux\u548cmacOS\u7b49\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7a33\u5b9a\u8fd0\u884c&#xff0c;\u4e14\u80fd\u8f7b\u677e\u4e0e\u5176\u4ed6\u7cfb\u7edf\u96c6\u6210\u3002<\/p>\n<p>\u672c\u6559\u7a0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u7528Python\u7f16\u5199\u4e00\u4e2a\u5b8c\u6574\u7684\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f&#xff0c;\u5305\u62ec&#xff1a;<\/p>\n<li>\u914d\u7f6eSMTP\u670d\u52a1\u5668\u53c2\u6570<\/li>\n<li>\u6784\u5efa\u90ae\u4ef6\u5185\u5bb9&#xff08;\u652f\u6301\u7eaf\u6587\u672c\u548cHTML\u683c\u5f0f&#xff09;<\/li>\n<li>\u6dfb\u52a0\u9644\u4ef6&#xff08;\u5982\u56fe\u7247\u3001\u6587\u6863\u7b49&#xff09;<\/li>\n<li>\u5b9e\u73b0\u6279\u91cf\u53d1\u9001\u529f\u80fd<\/li>\n<li>\u5904\u7406\u53d1\u9001\u5f02\u5e38\u548c\u65e5\u5fd7\u8bb0\u5f55<\/li>\n<li>\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\u7684\u6ce8\u610f\u4e8b\u9879<\/li>\n<p>\u6211\u4eec\u5c06\u901a\u8fc7\u5b9e\u9645\u6848\u4f8b\u6f14\u793a&#xff0c;\u4ece\u57fa\u7840\u7684\u5355\u5c01\u90ae\u4ef6\u53d1\u9001\u5230\u9ad8\u7ea7\u7684\u5b9a\u65f6\u6279\u91cf\u53d1\u9001\u529f\u80fd&#xff0c;\u5e2e\u52a9\u8bfb\u8005\u638c\u63e1\u5b8c\u6574\u7684\u90ae\u4ef6\u81ea\u52a8\u5316\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<hr \/>\n<h4>\u7406\u89e3SMTP\u534f\u8bae\u57fa\u7840<\/h4>\n<p>SMTP&#xff08;Simple Mail Transfer Protocol&#xff09;\u662f\u7528\u4e8e\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u6807\u51c6\u534f\u8bae\u3002Python\u901a\u8fc7smtplib\u5e93\u63d0\u4f9bSMTP\u534f\u8bae\u652f\u6301\u3002\u53d1\u9001\u90ae\u4ef6\u7684\u57fa\u672c\u6d41\u7a0b\u6d89\u53ca\u4e09\u4e2a\u5173\u952e\u73af\u8282&#xff1a;\u5efa\u7acbSMTP\u8fde\u63a5\u3001\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3001\u6784\u9020\u5e76\u53d1\u9001\u90ae\u4ef6\u5185\u5bb9\u3002<\/p>\n<p>\u7535\u5b50\u90ae\u4ef6\u901a\u5e38\u7531\u5934\u90e8&#xff08;From\/To\/Subject\u7b49&#xff09;\u548c\u6b63\u6587\u7ec4\u6210&#xff0c;\u53ef\u80fd\u5305\u542b\u7eaf\u6587\u672c\u3001HTML\u5185\u5bb9\u6216\u9644\u4ef6\u3002MIME&#xff08;Multipurpose Internet Mail Extensions&#xff09;\u6807\u51c6\u7528\u4e8e\u6269\u5c55\u90ae\u4ef6\u683c\u5f0f\u652f\u6301\u3002<\/p>\n<hr \/>\n<h4>\u914d\u7f6e\u5f00\u53d1\u73af\u5883<\/h4>\n<p>\u9700\u8981\u5b89\u88c5Python 3.6\u53ca\u4ee5\u4e0a\u7248\u672c\u3002\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u5fc5\u8981\u4f9d\u8d56\u5e93&#xff1a;<\/p>\n<p>pip install secure-smtplib email-validator<\/p>\n<p>\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\u9694\u79bb\u9879\u76ee\u4f9d\u8d56&#xff1a;<\/p>\n<p>python -m venv email_env<br \/>\nsource email_env\/bin\/activate  # Linux\/macOS<br \/>\nemail_env\\\\Scripts\\\\activate     # Windows<\/p>\n<hr \/>\n<h4>\u6784\u5efa\u90ae\u4ef6\u53d1\u9001\u51fd\u6570\u6838\u5fc3\u903b\u8f91<\/h4>\n<p>\u521b\u5efasend_email.py\u6587\u4ef6&#xff0c;\u5bfc\u5165\u57fa\u7840\u6a21\u5757&#xff1a;<\/p>\n<p>import smtplib<br \/>\nfrom email.mime.text import MIMEText<br \/>\nfrom email.mime.multipart import MIMEMultipart<br \/>\nfrom email.utils import formatdate<br \/>\nimport getpass<\/p>\n<p>\u521d\u59cb\u5316SMTP\u8fde\u63a5\u51fd\u6570&#xff1a;<\/p>\n<p>def connect_smtp_server(smtp_server, port, username, password):<br \/>\n    try:<br \/>\n        server &#061; smtplib.SMTP(smtp_server, port)<br \/>\n        server.starttls()<br \/>\n        server.login(username, password)<br \/>\n        return server<br \/>\n    except Exception as e:<br \/>\n        print(f&#034;\u8fde\u63a5SMTP\u670d\u52a1\u5668\u5931\u8d25: {str(e)}&#034;)<br \/>\n        raise<\/p>\n<p>\u90ae\u4ef6\u5185\u5bb9\u6784\u9020\u5668&#xff1a;<\/p>\n<p>def build_email(sender, receiver, subject, body, body_type&#061;&#039;plain&#039;):<br \/>\n    message &#061; MIMEMultipart()<br \/>\n    message[&#039;From&#039;] &#061; sender<br \/>\n    message[&#039;To&#039;] &#061; receiver<br \/>\n    message[&#039;Date&#039;] &#061; formatdate(localtime&#061;True)<br \/>\n    message[&#039;Subject&#039;] &#061; subject<\/p>\n<p>    if body_type &#061;&#061; &#039;html&#039;:<br \/>\n        content &#061; MIMEText(body, &#039;html&#039;)<br \/>\n    else:<br \/>\n        content &#061; MIMEText(body, &#039;plain&#039;)<\/p>\n<p>    message.attach(content)<br \/>\n    return message<\/p>\n<hr \/>\n<h4>\u5b9e\u73b0\u5b8c\u6574\u53d1\u9001\u6d41\u7a0b<\/h4>\n<p>\u4e3b\u53d1\u9001\u51fd\u6570\u6574\u5408\u6240\u6709\u7ec4\u4ef6&#xff1a;<\/p>\n<p>def send_email(smtp_config, email_content):<br \/>\n    try:<br \/>\n        server &#061; connect_smtp_server(<br \/>\n            smtp_config[&#039;server&#039;],<br \/>\n            smtp_config[&#039;port&#039;],<br \/>\n            smtp_config[&#039;username&#039;],<br \/>\n            smtp_config[&#039;password&#039;]<br \/>\n        )<\/p>\n<p>        message &#061; build_email(<br \/>\n            email_content[&#039;sender&#039;],<br \/>\n            email_content[&#039;receiver&#039;],<br \/>\n            email_content[&#039;subject&#039;],<br \/>\n            email_content[&#039;body&#039;],<br \/>\n            email_content.get(&#039;body_type&#039;, &#039;plain&#039;)<br \/>\n        )<\/p>\n<p>        server.sendmail(<br \/>\n            email_content[&#039;sender&#039;],<br \/>\n            email_content[&#039;receiver&#039;],<br \/>\n            message.as_string()<br \/>\n        )<\/p>\n<p>        server.quit()<br \/>\n        print(&#034;\u90ae\u4ef6\u53d1\u9001\u6210\u529f&#034;)<br \/>\n        return True<br \/>\n    except Exception as e:<br \/>\n        print(f&#034;\u90ae\u4ef6\u53d1\u9001\u5931\u8d25: {str(e)}&#034;)<br \/>\n        return False<\/p>\n<hr \/>\n<h4>\u6dfb\u52a0\u9644\u4ef6\u652f\u6301\u529f\u80fd<\/h4>\n<p>\u6269\u5c55\u90ae\u4ef6\u6784\u9020\u5668\u652f\u6301\u9644\u4ef6&#xff1a;<\/p>\n<p>from email.mime.application import MIMEApplication<br \/>\nfrom email.mime.base import MIMEBase<br \/>\nfrom email import encoders<br \/>\nimport os<\/p>\n<p>def add_attachment(message, file_path):<br \/>\n    with open(file_path, &#034;rb&#034;) as attachment:<br \/>\n        part &#061; MIMEBase(&#039;application&#039;, &#039;octet-stream&#039;)<br \/>\n        part.set_payload(attachment.read())<\/p>\n<p>    encoders.encode_base64(part)<br \/>\n    part.add_header(<br \/>\n        &#039;Content-Disposition&#039;,<br \/>\n        f&#039;attachment; filename&#061;{os.path.basename(file_path)}&#039;<br \/>\n    )<br \/>\n    message.attach(part)<\/p>\n<p>\u66f4\u65b0\u540e\u7684\u90ae\u4ef6\u6784\u9020\u5668&#xff1a;<\/p>\n<p>def build_email(sender, receiver, subject, body, attachments&#061;None, body_type&#061;&#039;plain&#039;):<br \/>\n    message &#061; MIMEMultipart()<br \/>\n    # &#8230; \u539f\u6709\u5934\u90e8\u8bbe\u7f6e\u4ee3\u7801 &#8230;<\/p>\n<p>    if attachments:<br \/>\n        for file_path in attachments:<br \/>\n            if os.path.exists(file_path):<br \/>\n                add_attachment(message, file_path)<br \/>\n            else:<br \/>\n                print(f&#034;\u8b66\u544a&#xff1a;\u9644\u4ef6\u6587\u4ef6\u4e0d\u5b58\u5728 {file_path}&#034;)<\/p>\n<p>    return message<\/p>\n<hr \/>\n<h4>\u5b9e\u73b0HTML\u90ae\u4ef6\u6a21\u677f<\/h4>\n<p>\u521b\u5efaHTML\u6a21\u677f\u6587\u4ef6template.html&#xff1a;<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;style&gt;<br \/>\n        body { font-family: Arial, sans-serif; }<br \/>\n        .header { color: #2c3e50; }<br \/>\n        .content { margin: 20px 0; }<br \/>\n        .footer { color: #7f8c8d; font-size: 0.8em; }<br \/>\n    &lt;\/style&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n    &lt;h1 class&#061;&#034;header&#034;&gt;${HEADER}&lt;\/h1&gt;<br \/>\n    &lt;div class&#061;&#034;content&#034;&gt;${CONTENT}&lt;\/div&gt;<br \/>\n    &lt;div class&#061;&#034;footer&#034;&gt;\u81ea\u52a8\u53d1\u9001\u4e8e ${DATE}&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>\u6dfb\u52a0\u6a21\u677f\u5904\u7406\u51fd\u6570&#xff1a;<\/p>\n<p>from string import Template<br \/>\nimport datetime<\/p>\n<p>def render_template(template_file, **kwargs):<br \/>\n    with open(template_file, &#039;r&#039;) as f:<br \/>\n        template &#061; Template(f.read())<\/p>\n<p>    if &#039;DATE&#039; not in kwargs:<br \/>\n        kwargs[&#039;DATE&#039;] &#061; datetime.datetime.now().strftime(&#039;%Y-%m-%d %H:%M&#039;)<\/p>\n<p>    return template.substitute(**kwargs)<\/p>\n<hr \/>\n<h4>\u5b89\u5168\u589e\u5f3a\u63aa\u65bd<\/h4>\n<p>\u5b9e\u73b0\u5bc6\u7801\u52a0\u5bc6\u5b58\u50a8&#xff1a;<\/p>\n<p>from cryptography.fernet import Fernet<br \/>\nimport base64<br \/>\nimport json<\/p>\n<p>class CredentialManager:<br \/>\n    def __init__(self, key_file&#061;&#039;.key&#039;):<br \/>\n        self.key &#061; self._load_or_generate_key(key_file)<\/p>\n<p>    def _load_or_generate_key(self, key_file):<br \/>\n        if os.path.exists(key_file):<br \/>\n            with open(key_file, &#039;rb&#039;) as f:<br \/>\n                return f.read()<br \/>\n        else:<br \/>\n            key &#061; Fernet.generate_key()<br \/>\n            with open(key_file, &#039;wb&#039;) as f:<br \/>\n                f.write(key)<br \/>\n            return key<\/p>\n<p>    def save_credentials(self, config_file, credentials):<br \/>\n        cipher &#061; Fernet(self.key)<br \/>\n        encrypted &#061; cipher.encrypt(json.dumps(credentials).encode())<br \/>\n        with open(config_file, &#039;wb&#039;) as f:<br \/>\n            f.write(encrypted)<\/p>\n<p>    def load_credentials(self, config_file):<br \/>\n        cipher &#061; Fernet(self.key)<br \/>\n        with open(config_file, &#039;rb&#039;) as f:<br \/>\n            encrypted &#061; f.read()<br \/>\n        return json.loads(cipher.decrypt(encrypted).decode())<\/p>\n<hr \/>\n<h4>\u5b8c\u6574\u5b9e\u73b0\u4ee3\u7801<\/h4>\n<p># email_sender.py<br \/>\nimport smtplib<br \/>\nimport os<br \/>\nimport json<br \/>\nimport getpass<br \/>\nimport datetime<br \/>\nfrom email.mime.text import MIMEText<br \/>\nfrom email.mime.multipart import MIMEMultipart<br \/>\nfrom email.mime.application import MIMEApplication<br \/>\nfrom email.mime.base import MIMEBase<br \/>\nfrom email import encoders<br \/>\nfrom email.utils import formatdate<br \/>\nfrom string import Template<br \/>\nfrom cryptography.fernet import Fernet<br \/>\nimport base64<\/p>\n<p>class EmailSender:<br \/>\n    def __init__(self, config_file&#061;&#039;config.json&#039;, key_file&#061;&#039;.key&#039;):<br \/>\n        self.config_file &#061; config_file<br \/>\n        self.cred_manager &#061; CredentialManager(key_file)<\/p>\n<p>        if not os.path.exists(config_file):<br \/>\n            self._setup_config()<\/p>\n<p>        self.config &#061; self.cred_manager.load_credentials(config_file)<\/p>\n<p>    def _setup_config(self):<br \/>\n        print(&#034;\u9996\u6b21\u4f7f\u7528\u9700\u8981\u8fdb\u884c\u914d\u7f6e&#034;)<br \/>\n        smtp_server &#061; input(&#034;SMTP\u670d\u52a1\u5668\u5730\u5740 (\u5982smtp.example.com): &#034;)<br \/>\n        port &#061; int(input(&#034;\u7aef\u53e3\u53f7 (587 for TLS): &#034;))<br \/>\n        username &#061; input(&#034;\u90ae\u7bb1\u5730\u5740: &#034;)<br \/>\n        password &#061; getpass.getpass(&#034;\u90ae\u7bb1\u5bc6\u7801\/\u6388\u6743\u7801: &#034;)<\/p>\n<p>        credentials &#061; {<br \/>\n            &#039;smtp_server&#039;: smtp_server,<br \/>\n            &#039;port&#039;: port,<br \/>\n            &#039;username&#039;: username,<br \/>\n            &#039;password&#039;: password<br \/>\n        }<\/p>\n<p>        self.cred_manager.save_credentials(self.config_file, credentials)<\/p>\n<p>    def connect_smtp(self):<br \/>\n        try:<br \/>\n            server &#061; smtplib.SMTP(self.config[&#039;smtp_server&#039;], self.config[&#039;port&#039;])<br \/>\n            server.starttls()<br \/>\n            server.login(self.config[&#039;username&#039;], self.config[&#039;password&#039;])<br \/>\n            return server<br \/>\n        except Exception as e:<br \/>\n            raise Exception(f&#034;SMTP\u8fde\u63a5\u5931\u8d25: {str(e)}&#034;)<\/p>\n<p>    def build_message(self, to, subject, body, body_type&#061;&#039;plain&#039;, attachments&#061;None, cc&#061;None, bcc&#061;None):<br \/>\n        msg &#061; MIMEMultipart()<br \/>\n        msg[&#039;From&#039;] &#061; self.config[&#039;username&#039;]<br \/>\n        msg[&#039;To&#039;] &#061; to<br \/>\n        msg[&#039;Subject&#039;] &#061; subject<br \/>\n        msg[&#039;Date&#039;] &#061; formatdate(localtime&#061;True)<\/p>\n<p>        if cc:<br \/>\n            msg[&#039;Cc&#039;] &#061; cc<br \/>\n        if bcc:<br \/>\n            msg[&#039;Bcc&#039;] &#061; bcc<\/p>\n<p>        if body_type &#061;&#061; &#039;html&#039;:<br \/>\n            msg.attach(MIMEText(body, &#039;html&#039;))<br \/>\n        else:<br \/>\n            msg.attach(MIMEText(body, &#039;plain&#039;))<\/p>\n<p>        if attachments:<br \/>\n            for file_path in attachments:<br \/>\n                if os.path.exists(file_path):<br \/>\n                    self._add_attachment(msg, file_path)<br \/>\n                else:<br \/>\n                    print(f&#034;\u9644\u4ef6\u4e0d\u5b58\u5728: {file_path}&#034;)<\/p>\n<p>        return msg<\/p>\n<p>    def _add_attachment(self, message, file_path):<br \/>\n        with open(file_path, &#034;rb&#034;) as f:<br \/>\n            part &#061; MIMEBase(&#039;application&#039;, &#039;octet-stream&#039;)<br \/>\n            part.set_payload(f.read())<\/p>\n<p>        encoders.encode_base64(part)<br \/>\n        part.add_header(<br \/>\n            &#039;Content-Disposition&#039;,<br \/>\n            f&#039;attachment; filename&#061;&#034;{os.path.basename(file_path)}&#034;&#039;<br \/>\n        )<br \/>\n        message.attach(part)<\/p>\n<p>    def send(self, to, subject, body, body_type&#061;&#039;plain&#039;, attachments&#061;None, cc&#061;None, bcc&#061;None):<br \/>\n        try:<br \/>\n            server &#061; self.connect_smtp()<br \/>\n            recipients &#061; [to]<br \/>\n            if cc:<br \/>\n                recipients &#043;&#061; cc.split(&#039;,&#039;)<br \/>\n            if bcc:<br \/>\n                recipients &#043;&#061; bcc.split(&#039;,&#039;)<\/p>\n<p>            msg &#061; self.build_message(to, subject, body, body_type, attachments, cc, bcc)<br \/>\n            server.sendmail(self.config[&#039;username&#039;], recipients, msg.as_string())<br \/>\n            server.quit()<br \/>\n            return True<br \/>\n        except Exception as e:<br \/>\n            print(f&#034;\u53d1\u9001\u5931\u8d25: {str(e)}&#034;)<br \/>\n            return False<\/p>\n<p>class CredentialManager:<br \/>\n    def __init__(self, key_file&#061;&#039;.key&#039;):<br \/>\n        self.key &#061; self._load_or_generate_key(key_file)<\/p>\n<p>    def _load_or_generate_key(self, key_file):<br \/>\n        if os.path.exists(key_file):<br \/>\n            with open(key_file, &#039;rb&#039;) as f:<br \/>\n                return f.read()<br \/>\n        else:<br \/>\n            key &#061; Fernet.generate_key()<br \/>\n            with open(key_file, &#039;wb&#039;) as f:<br \/>\n                f.write(key)<br \/>\n            return key<\/p>\n<p>    def save_credentials(self, config_file, credentials):<br \/>\n        cipher &#061; Fernet(self.key)<br \/>\n        encrypted &#061; cipher.encrypt(json.dumps(credentials).encode())<br \/>\n        with open(config_file, &#039;wb&#039;) as f:<br \/>\n            f.write(encrypted)<\/p>\n<p>    def load_credentials(self, config_file):<br \/>\n        cipher &#061; Fernet(self.key)<br \/>\n        with open(config_file, &#039;rb&#039;) as f:<br \/>\n            encrypted &#061; f.read()<br \/>\n        return json.loads(cipher.decrypt(encrypted).decode())<\/p>\n<p>def render_template(template_file, **kwargs):<br \/>\n    with open(template_file, &#039;r&#039;) as f:<br \/>\n        template &#061; Template(f.read())<\/p>\n<p>    if &#039;DATE&#039; not in kwargs:<br \/>\n        kwargs[&#039;DATE&#039;] &#061; datetime.datetime.now().strftime(&#039;%Y-%m-%d %H:%M&#039;)<\/p>\n<p>    return template.substitute(**kwargs)<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    sender &#061; EmailSender()<\/p>\n<p>    # \u793a\u4f8b1&#xff1a;\u53d1\u9001\u7eaf\u6587\u672c\u90ae\u4ef6<br \/>\n    sender.send(<br \/>\n        to&#061;&#034;recipient&#064;example.com&#034;,<br \/>\n        subject&#061;&#034;\u6d4b\u8bd5\u7eaf\u6587\u672c\u90ae\u4ef6&#034;,<br \/>\n        body&#061;&#034;\u8fd9\u662f\u4e00\u5c01\u6d4b\u8bd5\u90ae\u4ef6\u7684\u6b63\u6587\u5185\u5bb9\u3002&#034;<br \/>\n    )<\/p>\n<p>    # \u793a\u4f8b2&#xff1a;\u53d1\u9001\u5e26\u9644\u4ef6\u7684HTML\u90ae\u4ef6<br \/>\n    html_content &#061; &#034;&#034;&#034;<br \/>\n    &lt;h1&gt;HTML\u90ae\u4ef6\u6d4b\u8bd5&lt;\/h1&gt;<br \/>\n    &lt;p&gt;\u8fd9\u662f\u4e00\u5c01&lt;strong&gt;HTML\u683c\u5f0f&lt;\/strong&gt;\u7684\u6d4b\u8bd5\u90ae\u4ef6\u3002&lt;\/p&gt;<br \/>\n    &lt;p&gt;\u5f53\u524d\u65f6\u95f4&#xff1a;{}&lt;\/p&gt;<br \/>\n    &#034;&#034;&#034;.format(datetime.datetime.now().strftime(&#039;%Y-%m-%d %H:%M:%S&#039;))<\/p>\n<p>    sender.send(<br \/>\n        to&#061;&#034;recipient&#064;example.com&#034;,<br \/>\n        subject&#061;&#034;\u6d4b\u8bd5HTML\u90ae\u4ef6&#034;,<br \/>\n        body&#061;html_content,<br \/>\n        body_type&#061;&#039;html&#039;,<br \/>\n        attachments&#061;[&#039;report.pdf&#039;, &#039;data.xlsx&#039;]<br \/>\n    )<\/p>\n<p>    # \u793a\u4f8b3&#xff1a;\u4f7f\u7528\u6a21\u677f\u53d1\u9001\u90ae\u4ef6<br \/>\n    template_vars &#061; {<br \/>\n        &#039;HEADER&#039;: &#039;\u5b63\u5ea6\u62a5\u544a&#039;,<br \/>\n        &#039;CONTENT&#039;: &#039;\u8bf7\u67e5\u6536\u9644\u4ef6\u4e2d\u7684\u5b63\u5ea6\u8d22\u52a1\u62a5\u544a\u3002&#039;<br \/>\n    }<\/p>\n<p>    rendered &#061; render_template(&#039;template.html&#039;, **template_vars)<br \/>\n    sender.send(<br \/>\n        to&#061;&#034;manager&#064;example.com&#034;,<br \/>\n        subject&#061;&#034;\u5b63\u5ea6\u8d22\u52a1\u62a5\u544a&#034;,<br \/>\n        body&#061;rendered,<br \/>\n        body_type&#061;&#039;html&#039;,<br \/>\n        attachments&#061;[&#039;quarterly_report.pdf&#039;]<br \/>\n    )<\/p>\n<hr \/>\n<h4>\u9879\u76ee\u7ed3\u6784\u8bf4\u660e<\/h4>\n<p>\u5b8c\u6574\u9879\u76ee\u5e94\u5305\u542b\u4ee5\u4e0b\u6587\u4ef6&#xff1a;<\/p>\n<p>\/email_project<br \/>\n\u2502\u2500\u2500 email_sender.py       # \u4e3b\u7a0b\u5e8f<br \/>\n\u2502\u2500\u2500 config.json           # \u52a0\u5bc6\u7684\u914d\u7f6e\u6587\u4ef6<br \/>\n\u2502\u2500\u2500 .key                  # \u52a0\u5bc6\u5bc6\u94a5<br \/>\n\u2502\u2500\u2500 template.html         # HTML\u6a21\u677f<br \/>\n\u251c\u2500\u2500 attachments\/          # \u9644\u4ef6\u76ee\u5f55<br \/>\n\u2502   \u251c\u2500\u2500 report.pdf<br \/>\n\u2502   \u2514\u2500\u2500 data.xlsx<br \/>\n\u2514\u2500\u2500 requirements.txt      # \u4f9d\u8d56\u5217\u8868<\/p>\n<p>requirements.txt\u5185\u5bb9&#xff1a;<\/p>\n<p>secure-smtplib&#061;&#061;1.0.0<br \/>\ncryptography&#061;&#061;39.0.1<\/p>\n<hr \/>\n<h4>\u90e8\u7f72\u4e0e\u4f7f\u7528\u6307\u5357<\/h4>\n<li>\u9996\u6b21\u8fd0\u884c\u4f1a\u81ea\u52a8\u5f15\u5bfc\u914d\u7f6eSMTP\u53c2\u6570<\/li>\n<li>\u652f\u6301\u4e09\u79cd\u53d1\u9001\u6a21\u5f0f&#xff1a;\n<ul>\n<li>\u7eaf\u6587\u672c\u90ae\u4ef6<\/li>\n<li>HTML\u683c\u5f0f\u90ae\u4ef6<\/li>\n<li>\u5e26\u9644\u4ef6\u90ae\u4ef6<\/li>\n<\/ul>\n<\/li>\n<li>\u5bc6\u7801\u7b49\u654f\u611f\u4fe1\u606f\u91c7\u7528AES\u52a0\u5bc6\u5b58\u50a8<\/li>\n<li>\u53ef\u901a\u8fc7\u7ee7\u627fEmailSender\u7c7b\u6269\u5c55\u529f\u80fd<\/li>\n<hr \/>\n<h4>\u5b89\u5168\u6ce8\u610f\u4e8b\u9879<\/h4>\n<li>\u4e0d\u8981\u5c06.key\u6587\u4ef6\u63d0\u4ea4\u5230\u7248\u672c\u63a7\u5236<\/li>\n<li>\u5efa\u8bae\u4f7f\u7528\u5e94\u7528\u4e13\u7528\u5bc6\u7801\u800c\u975e\u8d26\u6237\u5bc6\u7801<\/li>\n<li>\u9644\u4ef6\u53d1\u9001\u524d\u5e94\u8fdb\u884c\u75c5\u6bd2\u626b\u63cf<\/li>\n<li>\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u6dfb\u52a0\u53d1\u9001\u9891\u7387\u9650\u5236<\/li>\n<p>\u901a\u8fc7\u672c\u6559\u7a0b&#xff0c;\u53ef\u4ee5\u6784\u5efa\u4e00\u4e2a\u529f\u80fd\u5b8c\u5907\u7684\u4f01\u4e1a\u7ea7\u90ae\u4ef6\u81ea\u52a8\u53d1\u9001\u7cfb\u7edf\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42&#xff0c;\u53ef\u8fdb\u4e00\u6b65\u6269\u5c55\u90ae\u4ef6\u961f\u5217\u3001\u53d1\u9001\u72b6\u6001\u8ddf\u8e2a\u7b49\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb136\u6b21\u3002\u636e\u7edf\u8ba1\uff0c\u5168\u7403\u6bcf\u5929\u53d1\u9001\u7684\u5546\u4e1a\u90ae\u4ef6\u8d85\u8fc730\u4ebf\u5c01\uff0c\u5176\u4e2d\u7ea640%\u662f\u901a\u8fc7\u81ea\u52a8\u5316\u7cfb\u7edf\u53d1\u9001\u7684\u3002Python\u51ed\u501f\u5176\u7b80\u6d01\u4f18\u96c5\u7684\u8bed\u6cd5\u548c\u5f3a\u5927\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u6210\u4e3a\u5b9e\u73b0\u90ae\u4ef6\u81ea\u52a8\u5316\u7684\u9996\u9009\u7f16\u7a0b\u8bed\u8a00\u3002\u5176\u6807\u51c6\u5e93\u4e2d\u7684smtplib\u548cemail\u6a21\u5757\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u90ae\u4ef6\u5904\u7406\u529f\u80fd\uff0c\u800c\u7b2c\u4e09\u65b9\u5e93\u5982yagmail\u66f4\u662f\u5c06\u53d1\u9001\u8fc7\u7a0b\u7b80\u5316\u5230\u6781\u81f4\u3002\u5e93\u63d0\u4f9bSMTP\u534f\u8bae\u652f\u6301\u3002\u53d1\u9001\u90ae\u4ef6\u7684\u57fa\u672c\u6d41\u7a0b\u6d89\u53ca\u4e09\u4e2a\u5173\u952e\u73af\u8282\uff1a\u5efa\u7acbSMTP\u8fde\u63a5\u3001\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3001\u6784\u9020\u5e76\u53d1\u9001\u90ae\u4ef6\u5185\u5bb9\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u5b9e\u9645\u6848\u4f8b\u6f14\u793a\uff0c\u4ece\u57fa\u7840\u7684\u5355\u5c01\u90ae\u4ef6\u53d1\u9001\u5230\u9ad8\u7ea7\u7684\u5b9a\u65f6\u6279\u91cf\u53d1\u9001\u529f\u80fd\uff0c\u5e2e\u52a9\u8bfb\u8005\u638c\u63e1\u5b8c\u6574\u7684\u90ae\u4ef6\u81ea\u52a8\u5316\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,4593,190,395],"topic":[],"class_list":["post-54853","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-4593","tag-190","tag-395"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/54853.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb136\u6b21\u3002\u636e\u7edf\u8ba1\uff0c\u5168\u7403\u6bcf\u5929\u53d1\u9001\u7684\u5546\u4e1a\u90ae\u4ef6\u8d85\u8fc730\u4ebf\u5c01\uff0c\u5176\u4e2d\u7ea640%\u662f\u901a\u8fc7\u81ea\u52a8\u5316\u7cfb\u7edf\u53d1\u9001\u7684\u3002Python\u51ed\u501f\u5176\u7b80\u6d01\u4f18\u96c5\u7684\u8bed\u6cd5\u548c\u5f3a\u5927\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u6210\u4e3a\u5b9e\u73b0\u90ae\u4ef6\u81ea\u52a8\u5316\u7684\u9996\u9009\u7f16\u7a0b\u8bed\u8a00\u3002\u5176\u6807\u51c6\u5e93\u4e2d\u7684smtplib\u548cemail\u6a21\u5757\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u90ae\u4ef6\u5904\u7406\u529f\u80fd\uff0c\u800c\u7b2c\u4e09\u65b9\u5e93\u5982yagmail\u66f4\u662f\u5c06\u53d1\u9001\u8fc7\u7a0b\u7b80\u5316\u5230\u6781\u81f4\u3002\u5e93\u63d0\u4f9bSMTP\u534f\u8bae\u652f\u6301\u3002\u53d1\u9001\u90ae\u4ef6\u7684\u57fa\u672c\u6d41\u7a0b\u6d89\u53ca\u4e09\u4e2a\u5173\u952e\u73af\u8282\uff1a\u5efa\u7acbSMTP\u8fde\u63a5\u3001\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3001\u6784\u9020\u5e76\u53d1\u9001\u90ae\u4ef6\u5185\u5bb9\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u5b9e\u9645\u6848\u4f8b\u6f14\u793a\uff0c\u4ece\u57fa\u7840\u7684\u5355\u5c01\u90ae\u4ef6\u53d1\u9001\u5230\u9ad8\u7ea7\u7684\u5b9a\u65f6\u6279\u91cf\u53d1\u9001\u529f\u80fd\uff0c\u5e2e\u52a9\u8bfb\u8005\u638c\u63e1\u5b8c\u6574\u7684\u90ae\u4ef6\u81ea\u52a8\u5316\u89e3\u51b3\u65b9\u6848\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/54853.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-13T04:10:04+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/54853.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/54853.html\",\"name\":\"\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-13T04:10:04+00:00\",\"dateModified\":\"2025-08-13T04:10:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/54853.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/54853.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/54853.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/54853.html","og_locale":"zh_CN","og_type":"article","og_title":"\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb136\u6b21\u3002\u636e\u7edf\u8ba1\uff0c\u5168\u7403\u6bcf\u5929\u53d1\u9001\u7684\u5546\u4e1a\u90ae\u4ef6\u8d85\u8fc730\u4ebf\u5c01\uff0c\u5176\u4e2d\u7ea640%\u662f\u901a\u8fc7\u81ea\u52a8\u5316\u7cfb\u7edf\u53d1\u9001\u7684\u3002Python\u51ed\u501f\u5176\u7b80\u6d01\u4f18\u96c5\u7684\u8bed\u6cd5\u548c\u5f3a\u5927\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u6210\u4e3a\u5b9e\u73b0\u90ae\u4ef6\u81ea\u52a8\u5316\u7684\u9996\u9009\u7f16\u7a0b\u8bed\u8a00\u3002\u5176\u6807\u51c6\u5e93\u4e2d\u7684smtplib\u548cemail\u6a21\u5757\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u90ae\u4ef6\u5904\u7406\u529f\u80fd\uff0c\u800c\u7b2c\u4e09\u65b9\u5e93\u5982yagmail\u66f4\u662f\u5c06\u53d1\u9001\u8fc7\u7a0b\u7b80\u5316\u5230\u6781\u81f4\u3002\u5e93\u63d0\u4f9bSMTP\u534f\u8bae\u652f\u6301\u3002\u53d1\u9001\u90ae\u4ef6\u7684\u57fa\u672c\u6d41\u7a0b\u6d89\u53ca\u4e09\u4e2a\u5173\u952e\u73af\u8282\uff1a\u5efa\u7acbSMTP\u8fde\u63a5\u3001\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3001\u6784\u9020\u5e76\u53d1\u9001\u90ae\u4ef6\u5185\u5bb9\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u5b9e\u9645\u6848\u4f8b\u6f14\u793a\uff0c\u4ece\u57fa\u7840\u7684\u5355\u5c01\u90ae\u4ef6\u53d1\u9001\u5230\u9ad8\u7ea7\u7684\u5b9a\u65f6\u6279\u91cf\u53d1\u9001\u529f\u80fd\uff0c\u5e2e\u52a9\u8bfb\u8005\u638c\u63e1\u5b8c\u6574\u7684\u90ae\u4ef6\u81ea\u52a8\u5316\u89e3\u51b3\u65b9\u6848\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/54853.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-13T04:10:04+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/54853.html","url":"https:\/\/www.wsisp.com\/helps\/54853.html","name":"\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-13T04:10:04+00:00","dateModified":"2025-08-13T04:10:04+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/54853.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/54853.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/54853.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u8fdb\u9636\u5411:Python\u7f16\u5199\u81ea\u52a8\u5316\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/54853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=54853"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/54853\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=54853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=54853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=54853"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=54853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}