[Python] Google Drive API: files.get_media()

Discussão em 'Python' iniciado por Stack, Janeiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have been trying for weeks to just get a docx file from Google Drive using their API. I understand the way to do this would be to use the get_media method, which has worked and I am able to get the byte stream. However, every single method I have used to convert this to text, has failed. All I want is the text from a docx file in google drive, so if anyone has any suggestions that would be extremely appreciated.

    service = build("drive", "v3", credentials=creds)
    file_id = real_file_id
    request = service.files().get_media(fileId=file_id)

    file = io.BytesIO()
    downloader = MediaIoBaseDownload(file, request)
    done = False
    while done is False:
    status, done = downloader.next_chunk()
    print(f"Download {int(status.progress() * 100)}.")


    This gets me the bytes of the file but when I attempt to decode, I get invalid continuation bytes and then even ignoring errors, it still does not work. If anyone has done this before or can help me out I would GREATLY appreciate it.

    Continue reading...

Compartilhe esta Página