0

I'm trying to extract a rar file using the python library rarfile.RarFile (on windows), but it keeps giving me

TypeError: 'NoneType' object is not iterable

import rarfile
rarfile=r"E:\rarFiles\CH6ED-(09_14_2021 Tue-10_10_33.99).rar"

with rarfile.RarFile(rarfile) as file:
   file.extractall(path="directory",pwd="password")

can anyone please help me get rid of with this error?


I changed my code to this

import rarfile

with rarfile.RarFile(r"E:\rarFiles\CH6ED-(09_14_2021 Tue-10_10_33.99).rar") as file:
   file.extractall(path="C:\Users\Joanna\Desktop",pwd="123")

but I gave me the same error

3
  • use a other variable name for the path as you have a library with the name rarfile Commented Oct 6, 2021 at 1:28
  • I changed my code, but it gave me the same error Commented Oct 6, 2021 at 1:39
  • Is that really all of your code? When I tried pip install rarfile and just pasted in your 3 lines, I get rarfile.RarCannotExec: Cannot find working tool (seems related to stackoverflow.com/a/43527756/114900 ). Commented Oct 6, 2021 at 2:26

2 Answers 2

1

When you do rarfile=r"E:\folder\myrarfile" you are overwriting the name rarfile that was associated with the module you imported, and now is pointing to the string object r"E:\folder\myrarfile". You have to name your variable that holds the path to the .rar file to something else. As a general advice, don't name your variables the same name used for imports.

Sign up to request clarification or add additional context in comments.

1 Comment

I changed my code, but it gave me the same error. I updated my question
1

try

rarfile.RarFile(
r"E:\rarFiles\CH6ED-(09_14_2021 Tue-10_10_33.99).rar"
).extractall(path="C:\Users\Joanna\Desktop",pwd="123")

3 Comments

still got the error:(
are you sure that path is correct? copy the file to the same folder where you run the script, and rename it to a name without the underlines and dashes.
you can also try with PathLib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.