Python Forum
That compression method is not supported
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
That compression method is not supported
#1
Greetings!
I used this snippet for a while but yesterday the script crashed...
with the error:
'That compression method is not supported'
I'm expecting try/except part of the scripts to skip the 'Bad' file but it did not...
Part of the script:
from zipfile import ZipFile
from zipfile import BadZipfile
from pathlib import Path
# Some code here
try :
	with ZipFile(ef) as zz:
			for file in zz.namelist():
				zp_name = Path(file).name 
				#print(f" ZIP NAME : {zp_name}")
				if 'Trace' in file :
					zz.extract(file,temp_temp_dr_out)
except BadZipfile as er :
	print(f" Bad ZIP found -> {er}")
	continue 
Any help is appreciated.
Thank you.
Reply
#2
Please try to use a topic that represents the question asked in the post. Your question is about try/except. You didn't ask anything about compression methods. Using a good topic gives your post value. Others having questions about the same topic will be able to find your post and maybe you can help them.

Think about how try/except works. If an exception is raised, where does the program jump too? If you think about how try/except works instead of why it didn't work here, the solution is obvious.
tester_V likes this post
Reply
#3
I thought it should print the error and continue.
Am I mistaken?
Thank you.
Reply
#4
That is exactly what it does in your program. It jumps to the exception body, which prints a message and continues. Why does that end the loop?
Reply
#5
Sorry for the confusion!
I'm expecting the program to "skip" a bad zip file if found and take the next one.
I'm not expecting the program to crash, I'm expecting it to print the "error" but it does crush.
That is strange.

THank you.
Reply
#6
What error do you get? Post the full traceback. Obviously it's not BadZipfile, because it's not captured. From what I see on Internet, it's NotImplementedError, so capture that error too in the except clause.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Buran might be right. What is the error message? Does it say : Bad ZIP found -> That compression method is not supported? If the message starts with "Bad ZIP found", your exception handler caught the error. If it doesn't, the exception was not caught. You've been posting to this forum for over 2 years. You know how it works. Post full error messages and the complete error trace.

Either way, your try/except will not work as you expect. If you catch the exception, the program will jump HERE (marked below) and execute the code in the exception block.

from zipfile import ZipFile
from zipfile import BadZipfile
from pathlib import Path
# Some code here
try :
    with ZipFile(ef) as zz:
            for file in zz.namelist():
                zp_name = Path(file).name 
                #print(f" ZIP NAME : {zp_name}")
                if 'Trace' in file :
                    zz.extract(file,temp_temp_dr_out)
except BadZipfile as er :
    print(f" Bad ZIP found -> {er}")   # <-- JUMP TO HERE IF BadZipFile exception
    continue 
Is the exception body inside or outside the loop?
tester_V likes this post
Reply
#8
you are right, it is the case:
'That compression method is not supported? If the message starts with "Bad ZIP found", your exception handler caught the error. If it doesn't, the exception was not caught'

I added one more exception, and the script does not stop anymore.
        except BadZipfile as er :
            print(f" Bad ZIP found -> {er}")
            continue 
        except RuntimeError:
           continue 
Thank you for your help! Dance
I really appreciate it...
Reply
#9
You don't need to add an exception, you just need to move it inside the loop. You don't need the continue statements either.
tester_V likes this post
Reply
#10
I see your point, deanhystad. I'll do that!
Thank you very much!
You guys are great! Smile
Tester_V
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  compression module for lz4? Skaperen 1 1,570 Oct-27-2021, 01:47 PM
Last Post: DeaD_EyE
  CPC File Format (Cartesian Perceptual Compression) - Can Python Convert / Handle Them PSKrieger 2 2,466 Nov-11-2020, 02:57 PM
Last Post: PSKrieger
  Rebuild LZ compression from C code via Python's LZMA module TD2 0 1,865 Apr-25-2019, 02:42 PM
Last Post: TD2
  problem with lambda and list compression Prince_Bhatia 1 2,352 Aug-06-2018, 11:50 AM
Last Post: ichabod801
  Compression/Decompression Code not working Zanbezi 3 3,703 May-10-2017, 04:46 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020