3

Есть функция загрузки аудио:

async def upload_audio_message(api, multipart_data, peer_id):
    """Upload audio file `multipart_data` and return Attachment for sending to user with id `peer_id`(possibly)"""

    sender = api.get_default_sender("docs.getMessagesUploadServer")
    client = api.get_current_sender("docs.getMessagesUploadServer", sender=sender)

    data = aiohttp.FormData()
    data.add_field('file', multipart_data, filename="message.mp3", content_type='multipart/form-data')

    values = {'type': "audio_message", 'peer_id': peer_id}

    if client.group_id:
        values['group_id'] = client.group_id

    response = await api(sender=sender).docs.getMessagesUploadServer(**values)

    if not response or not response.get('upload_url'):
        return None

    upload_url = response['upload_url']

    async with aiohttp.ClientSession() as sess:
        async with sess.post(upload_url, data=data) as resp:
            result = json.loads(await resp.text())

    if not result:
        return None

    data = dict(file=result['file'])
    result = (await api(sender=sender).docs.save(**data))[0]

    return Attachment.from_upload_result(result, "doc")

Пытаюсь открыть аудио файл что бы загрузить его но что-то я делаю не так помогите пожалуйста:

answer_file = wave.open(self.get_path("winer.mp3"), "rb")
audio = await upload_audio_message(self.api, answer_file, msg.user_id)
answer_file.close()

raise Error('file does not start with RIFF id') wave.Error: file does not start with RIFF id

3
  • 2
    А ваша либа поддерживает mp3? Видя сообщение - скорее всего нет.
    – nick_n_a
    13 июн 2018 в 10:39
  • Мне кажется дело не только в ней а еще в моем коде
    – Lumo
    13 июн 2018 в 10:40
  • Название методов похоже на vk :) Автор, а точно нужно парсить файл? Мб нужно просто считать и отправить его? Попробуйте: answer_file = open(self.get_path("winer.mp3"), "rb")
    – gil9red
    13 июн 2018 в 11:14

1 ответ 1

3

Ошибка:

wave.Error: file does not start with RIFF id

Используемый модуль wave умеет работать только с форматом WAV, поэтому в этом коде возникает та ошибка:

answer_file = wave.open(self.get_path("winer.mp3"), "rb")

Ваш ответ

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

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