D
D
Dunge12020-02-05 12:56:52
Python
Dunge1, 2020-02-05 12:56:52

The vk_api picture is not sent to python. What to do?

I made a script to send a picture from the device, but only my message is sent, what should I do?
The script itself:

elif event.text == '!тест':
   data = vk.photos.getMessagesUploadServer(peer_id = event.peer_id)
   upload_url = data['upload_url']
   img = {'photo': ('blank.jpg', open(r'/sdcard/Download/blank.jpg', 'rb'))}
   request = requests.post(upload_url, files = img)
   print(request.text)
   result = json.loads(request.text)
   server = result['server']
   photo = result['photo']
   hash = result['hash']
   sphoto = vk.photos.saveMessagesPhoto(server = server, photo = photo, hash = hash)
   vk.messages.send(peer_id = event.peer_id, random_id = 0, message = str(''), attachment = sphoto)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-02-08
@SoreMix

Attachments need to be loaded in format
<type><owner_id>_<media_id>
A in sphotoyour data array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question