1

My code is ran in Python 3.8.2, name of file is main.py

enter image description here

After I run python main.py, i receive the error like this:

enter image description here

My path to file is : C:\Users\84165\Desktop\KLTN-backend\upload\thainq\Test.docx

I have searched in stackoverflow for hours about this error, but there is no solution.

Am i wrong in somewhere? Thank you in advance.

Quang Thái
  • 649
  • 5
  • 17
  • 1
    This error usually happens when you use `r` instead of `rb` when we do `with open` the file. But, it looks like you are already using `rb`. Did you try hardcoding the file path? Also, try a different input file. – Jinto Lonappan Jun 07 '20 at 18:11
  • @JintoLonappan i used "rb" as open file as binary file followed by mammoth docs. I tried hardcoding the path but nothing changes – Quang Thái Jun 08 '20 at 01:19
  • I tried your exact code and I got the result. See below: ```/code/python/testers/upload/thainq/Test.docx

    This is a test DOCX file

    To verify the mammoth package in Python

    None``` . Try creating a new virtual environment and re-install mammoth. Sorry, not sure how else to help
    – Jinto Lonappan Jun 08 '20 at 02:38
  • 1
    @JintoLonappan i've created an issue on this github package. Maybe i'm wrong in somewhere. Thank you for spending time! – Quang Thái Jun 08 '20 at 02:46

1 Answers1

2

There are two reasons this may be happening

  1. Your docx file is completely empty (0 bytes).
  2. The docx file your code is operating on through mammoth.convert_to_html or mammoth.extract_raw_text is currently open. Please close your file, then run the script.
Rysicin
  • 95
  • 1
  • 10