I am trying to unrar files uploaded by users in django web application. I have gone through different approaches but none of them are working for me. The below methods work fine in my local OS (Ubuntu 18.04), but n't working in the server. I am using Python 3.6.
import rarfile - here 'rarfile' is imported from python3.6/site-packages/rarfile. It is giving this error -
bsdtar: Error opening archive: Failed to open '--'
Following the steps suggested here, I installed 'unrar'.
from unrar import rarfile - here it's being imported from python3.6/site-packages/unrar/
But this gave the error -
LookupError: Couldn't find path to unrar library.
So to solve the issue, I followed the steps mentioned here, and created UnRaR executable, and also set the path in my environment. This works fine in local, but unable to understand how to do the same in 'production environment'.
import patoolib - importing from patool
I also tried implementing patool, which worked fine in local but not in production and I am getting this error -
patoolib.util.PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z),
This has become a big blocker in my application, can anyone please explain how to solve the problem.
Code snippet for rarfile -
import rarfile
.....
rf = rarfile.RarFile(file_path)
rf.extractall(extract_to_path)
Code snippet for patool -
import patoolib
...
patoolib.extract_archive(file_path, outdir=extract_to_path)