如何更改Python email.mim中的默认端点

2024-04-27 03:28:41 发布

您现在位置:Python中文网/ 问答频道 /正文

当我使用mime模块时,我想更改默认的结束行(即\n

from email.mime.text import MIMEText
a = MIMEText('hello')
a['From'] = 'stack'
print(a.as_bytes())

结果是

b'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\nFrom: stack\n\nhello'

但是,我想在HTTP请求中使用它(原因是here),所以我需要将分隔的\n改为\r\n。有什么方法可以实现吗


Tags: 模块textfromimporthellobytesstackemail