BadRarFile when extracting single file using RarFile in Python

Viewed 275

I need to extract a single file (~10kB) from many very large RAR files (>1Gb). The code below shows a basic implementation of how I'm doing this.

from rarfile import RarFile

rar_file='D:\\File.rar'
file_of_interest='Folder 1/Subfolder 2/File.dat'
output_folder='D:/Output'

rardata = RarFile(rar_file)
rardata.extract(file_of_interest, output_folder)
rardata.close()

However, the extract instruction is returning the following error: rarfile.BadRarFile: Failed the read enough data: req=16384 got=52

When I open the file using WinRAR, I can extract the file successfully, so I'm sure the file isn't corrupted.

I've found some similar questions, but not a definite answer that worked for me.

Can someone help me to solve this error?

Additional info:

  • Windows 10 build 1909
  • Spyder 5.0.0
  • Python 3.8.1

Complete traceback of the error:

Traceback (most recent call last):

  File "D:\Test\teste_rar_2.py", line 27, in <module>
    rardata.extract(file_of_interest, output_folder)

  File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\site-packages\rarfile.py", line 826, in extract
    return self._extract_one(inf, path, pwd, True)

  File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\site-packages\rarfile.py", line 912, in _extract_one
    return self._make_file(info, dstfn, pwd, set_attrs)

  File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\site-packages\rarfile.py", line 927, in _make_file
    shutil.copyfileobj(src, dst)

  File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\shutil.py", line 79, in copyfileobj
    buf = fsrc.read(length)

  File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\site-packages\rarfile.py", line 2197, in read
    raise BadRarFile("Failed the read enough data: req=%d got=%d" % (orig, len(data)))

BadRarFile: Failed the read enough data: req=16384 got=52
0 Answers
Related