问题描述
我正在互相粘贴两个图像以用作我的机器人的Discord文件,但是每当我尝试将完成的图像数据从PIL和BytesIO馈送到Discord时,我都会收到一个奇怪的错误:UnicodeDecodeError :'utf-8'编解码器无法解码位置0的字节0x89:无效的起始字节
这是我的代码(或相关的块):
async with aiohttp.ClientSession() as session:
async with session.get(avurl) as second_image:
image_bytes = await second_image.read()
with Image.open(BytesIO(image_bytes)).convert("RGB") as first_image:
output_buffer = BytesIO()
first_image.save(output_buffer,"png")
output_buffer.seek(0)
async with aiohttp.ClientSession() as session:
async with session.get("https://i.imgur.com/dNS0WJO.png") as second_image:
image_bytes = await second_image.read()
with Image.open(BytesIO(image_bytes)) as second_image:
output_buffer = BytesIO()
second_image.save(output_buffer,"png")
output_buffer.seek(0)
first_image.paste(second_image,(0,0))
buf = io.BytesIO()
first_image.save(buf,"png")
first_image = first_image.getvalue()
buf = buf.getvalue()
file = discord.File(fp=buf,filename="pfp.png")
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)