【问题标题】:Sending Email From Databricks Notebooks从 Databricks 笔记本发送电子邮件
【发布时间】:2019-05-22 21:50:09
【问题描述】:

我想从 databricks 笔记本发送电子邮件,基于这篇文章:https://docs.databricks.com/user-guide/faq/send-email.html

我正在按照步骤进行操作,但出现错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte 而且,我认为,原因是因为在函数 makeCompatibleImage 内部我们有这个片段:val = "" % base64.standard_b64encode(png.read()),并且base64.standard_b64encode可能有问题

import numpy as np
import matplotlib.pyplot as plt

# Compute pie slices
N = 20
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
radii = 10 * np.random.rand(N)
width = np.pi / 4 * np.random.rand(N)

ax = plt.subplot(111, projection='polar')
bars = ax.bar(theta, radii, width=width, bottom=0.0)

# Use custom colors and opacity
for r, bar in zip(radii, bars):
    bar.set_facecolor(plt.cm.viridis(r / 10.))
    bar.set_alpha(0.5)
# Convert image add append to html array
html.append(makeCompatibleImage(ax))

#
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<command-890455078841631> in <module>()
     16     bar.set_alpha(0.5)
     17 # Convert image add append to html array
---> 18 html.append(makeCompatibleImage(ax))

<command-890455078841625> in makeCompatibleImage(image, withLabel)
     11   val = None
     12   with open(imageName) as png:
---> 13     val = "<img src='data:image/png;base64,%s'>" % base64.standard_b64encode(png.read())
     14 
     15   displayHTML(val)

/databricks/python/lib/python3.6/codecs.py in decode(self, input, final)
    319         # decode input (taking the buffer into account)
    320         data = self.buffer + input
--> 321         (result, consumed) = self._buffer_decode(data, self.errors, final)
    322         # keep undecoded input until the next call
    323         self.buffer = data[consumed:]

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

我想知道如何复制这篇文章。

【问题讨论】:

    标签: html-email databricks


    【解决方案1】:

    makeCompatibleImage 函数中添加以下代码,以二进制模式读取文件,对我有用:

     with open(imageName, 'rb') as png:
    

    【讨论】:

      猜你喜欢
      • 2019-12-26
      • 1970-01-01
      • 1970-01-01
      • 2011-09-16
      • 1970-01-01
      • 2015-07-21
      • 2011-04-28
      • 1970-01-01
      • 2020-03-26
      相关资源
      最近更新 更多