0

При получении файла от пользователя получаю следующий словарь: {"attach1_type": "doc", "attach1": "742288495_658873163"}

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType

def main():
    vk_session = vk_api.VkApi(token='token')
    vk = vk_session.get_api()

for event in VkLongPoll(vk_session).listen():
    if event.type == VkEventType.MESSAGE_NEW and event.to_me:
        if event.attachments:
            if event.attachments["attach1_type"] == "doc":
                document = event.attachments["attach1"]
                response = vk.docs.getById(docs=document)
                print(response)

Когда пытаюсь получить больше информации о документе, используя docs.getById, то получаю пустой массив. Что я делаю не так?

2 ответа 2

0

Попробуй так:

from vk_api.exceptions import VkApiError

def main():
    vk_session = vk_api.VkApi(token='token')
    vk = vk_session.get_api()

    for event in VkLongPoll(vk_session).listen():
        if event.type == VkEventType.MESSAGE_NEW and event.to_me:
            if event.attachments:
                if event.attachments["attach1_type"] == "doc":
                    document_id = int(event.attachments["attach1"])
                    try:
                        response = vk.docs.getById(docs=document_id)
                        print(response)
                    except VkApiError as e:
                        print("Ошибка VK API:", e)

0

Проблема заключалась в том, что файл был в закрытом доступе, а не в открытом

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.