【发布时间】:2020-05-23 07:10:39
【问题描述】:
我正在制作一个 python3 脚本,在特定时间间隔后将屏幕截图发送到我的邮件。但我收到的是 bsee64 格式的屏幕截图,而不是 png/jpg 格式。请将该功能添加到我的代码中
代码在这里
from _multiprocessing import send
from typing import BinaryIO
from PIL import ImageGrab
import base64, os, time
import smtplib
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
# [!]Remember! You need to enable 'Allow less secure apps' in your #google account
# Enter your gmail username and password
s.login("zainali90900666@gmail.com", "password")
# message to be sent
while True:
snapshot = ImageGrab.grab() # Take snap
file = "scr.jpg"
snapshot.save(file)
f: BinaryIO = open('scr.jpg', 'rb') # Open file in binary mode
data = f.read()
data = base64.b64encode(data) # Convert binary to base 64
f.close()
os.remove(file)
message = data # data variable has the base64 string of screenshot
# Sender email, recipient email
s.sendmail("zainali90900666@gmail.com", "zainali90900666@gmail.com", message)
time.sleep(some_time)
【问题讨论】:
标签: python python-3.x python-requests