发送截图

时间:2018-11-13 01:06:14

标签: python typeerror

这是我的代码,它应该向我发送带有屏幕截图的电子邮件,但我收到以下错误。

Traceback (most recent call last):
  File "email_screenshot.py", line 34, in <module>
    my_screenshot.start()
  File "email_screenshot.py", line 26, in start
    with open(im) as file:
TypeError: coercing to Unicode: need string or buffer, PngImageFile found 

这是我应该怎么做才能摆脱此python2.7代码中的类型错误。

import pyscreenshot as ImageGrab
import smtplib
import base64


class Screenshot:
        def __init__(self, email, password):
            self.screenshot = ImageGrab.grab
            self.email = email
            self.password = password

        def send_screenshot(self):
            self.send_email(self.email, self.password, self.screenshot)
            report = self.send_screenshot
            report.start()

        def send_email(self, email, password, message):
            server = smtplib.SMTP("smtp.gmail.com", 587)
            server.starttls()
            server.login(email, password)
            server.sendmail(email, email, message)
            server.quit()

        def start(self):
            im = ImageGrab.grab()
            with open(im) as file:
                file.write(base64.b64decode(im))
            with im:
                self.send_screenshot()
                im.join()


my_screenshot = Screenshot("myuser", "mypass",)
my_screenshot.start()

有人有什么想法

0 个答案:

没有答案