T
T
Timtaran2021-05-08 13:04:04
Python
Timtaran, 2021-05-08 13:04:04

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)

Photo:
609661db4f4f6469010608.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timtaran, 2021-05-08
@Timtaran

Solution:
Don't specify the peer_id of the conversation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question