Answer the question
In order to leave comments, you need to log in
How to upload photo to community wall with vk api python?
The task is to upload a photo from a computer and send it to the community proposal. The code described below works great in the method of sending photos to messages to the user, but it doesn’t want to upload them to the wall.
import vk_api
from vk_api import VkUpload
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.utils import get_random_id
import requests
import csv
import json
#Процесс авторизации
token = #Тут мой токен
authorize = vk_api.VkApi(token = token)
longpoll = VkLongPoll(authorize)
photo = 'photo/2.jpg' # Сюда помещаю фото из папки
image = photo
upload = VkUpload(authorize)
upload_image = upload.photo_messages(photos = image)[0]
attachments = 'photo{}_{}'.format(upload_image['owner_id'], upload_image['id'])
href = "'" + attachments + "'" #Проверял, на выходе получается результат по шаблону 'photo100172_166443618'
# Функция отправки на стену
def send_content( href):
authorize.method('wall.post', {'owner_id': id Сообщества, 'message': 'Привет', 'attachments': href })
Answer the question
In order to leave comments, you need to log in
1. Why do we need quotes in ?
2. Upload a photo to the server to send to the LAN, while you yourself are trying to upload a photo to the wall. Use the method to upload to the wall, oddly enough. photo_wall https://vk-api.readthedocs.io/en/latest/upload.htmlhref = "'" + attachments + "'"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question