Mailgun 内联图像 utf-8 png
Mailgun inline image utf-8 png
我正在尝试从 Mailgun 获取内联图像示例以使用 Python,但由于某种原因,当我添加 png 图像时它会抛出 Unicode 错误。这是我正在使用的示例函数,将 jpg 更改为 png。
def send_inline_image():
return requests.post(
"https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages",
auth=("api", "YOUR_API_KEY"),
files=[("inline", open("files/test.png"))],
data={"from": "Excited User <YOU@YOUR_DOMAIN_NAME>",
"to": "bar@example.com",
"subject": "Hello",
"text": "Testing some Mailgun awesomness!",
"html": '<html>Inline image here: <img src="cid:test.png"></html>'})
这是抛出的异常:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
没有内联图像,一切都按预期工作。我怎样才能让它与 png 图像一起使用?
尝试将 'rb' 添加到您的 open() 调用中:
files=[("inline", open("files/test.png", 'rb'))]
我正在尝试从 Mailgun 获取内联图像示例以使用 Python,但由于某种原因,当我添加 png 图像时它会抛出 Unicode 错误。这是我正在使用的示例函数,将 jpg 更改为 png。
def send_inline_image():
return requests.post(
"https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages",
auth=("api", "YOUR_API_KEY"),
files=[("inline", open("files/test.png"))],
data={"from": "Excited User <YOU@YOUR_DOMAIN_NAME>",
"to": "bar@example.com",
"subject": "Hello",
"text": "Testing some Mailgun awesomness!",
"html": '<html>Inline image here: <img src="cid:test.png"></html>'})
这是抛出的异常:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
没有内联图像,一切都按预期工作。我怎样才能让它与 png 图像一起使用?
尝试将 'rb' 添加到您的 open() 调用中:
files=[("inline", open("files/test.png", 'rb'))]