Answer the question
In order to leave comments, you need to log in
How to upload and send a photo to VKontakte private messages via vk_api in python?
The second day I'm trying to figure out how to upload and send a photo to personal messages on VKontakte via vk_api. I need to upload a photo from a computer to a personal account (not to an album). I read the documentation and forums, but I did not find a clear answer. Please explain to me exactly how to do this and what to substitute where.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
If you still need:
def send_photos(chat_id, text, owner, album): # Отправляем фото
count = randrange(vk.method('photos.get', {'owner_id': owner, 'album_id': album, 'count': 1})["count"])
photos = vk.method('photos.get', {'owner_id': owner, 'album_id': album, 'count': 1, 'offset': count})
t = choice(photos["items"])
try:
vk.method('messages.send',
{'random_id': 0000000, 'chat_id': chat_id, 'message': text,
'attachment': ('photo' + str(owner) + '_' + str(t["id"]))})
except vk_api.CAPTCHA_ERROR_CODE as error_msg:
write(chat_id, error_msg)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question