Answer the question
In order to leave comments, you need to log in
How to fix [1] Unknown error occurred vk_api?
When trying to load an image, an error occurs:
[1] Unknown error occurred
In this case, if you save the image to a file, everything is ok.
the code -
def image2bytes(img, format):
image_content = BytesIO()
img.seek(0)
img.save(image_content, format=format)
image_content.seek(0)
return image_content
@bot.loop_wrapper.interval(seconds=1)
async def s30():
im = Image.new('RGB', (500, 500), color=('#72DD69'))
dt_now = str(datetime.datetime.now())
font = ImageFont.truetype("D:\\16596.ttf", 28)
draw_text = ImageDraw.Draw(im)
draw_text.text(
(0, 250),
dt_now,
fill=('#FFFFFF'),
font=font
)
img=image2bytes(im, 'PNG')
#file = open('D:\\test.jpg', 'wb')
#file.write(img.read())
#file.close()
photo = await PhotoMessageUploader(bot.api).upload(img, peer_id=2000000001)
await bot.api.messages.send(random_id=0, chat_id=1, attachment=photo)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question