How to send a picture generated in the PIL through a POST request in the format multipart / form-data. Here is the image transfer code
requests.post(upload_url, files = {'file': open(filename, 'rb')}) The task is to transfer the image without saving it as a separate file.
Tried through BytesIO. Does not work.
img = pic_gen.gen_obj(parcer.main()) #Создаю изображение buf = io.BytesIO() img.save(buf, format='PNG') buf.seek(0, 0) #a = io.BufferedReader(buf) album_id = ID альбома group_id = ID группы token = 'ТОКЕН' api = vk.API(vk.Session(access_token=token), v=5.92) upload_url = api.photos.getWallUploadServer(group_id=group_id)['upload_url'] resp = requests.post(upload_url, files = {'file': buf.getvalue()}).json() s = api.photos.saveWallPhoto(group_id=group_id, server = resp['server'], photo= resp['photo'], hash = resp['hash']) api.wall.post(owner_id = -group_id, message="Test!", attachments=f"photo{s[0]['owner_id']}_{s[0]['id']}")
io.BytesIO- andreymal pm