473,289 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Re: Zipfile module errors

On Jun 4, 8:06 pm, jwesonga <crazylun...@gmail.comwrote:
Hi,

I have a python script that supposed to go through a folder, pick the
zipped files, unzip them and process the data inside. I'm not sure
where i'm going wrong with this script because it all seems correct:
Nothing is ever as it seems. Let's try to work backwards from the
error message ... and we don't need your magnificent script, just the
traceback will do for now, so:

[ big snip]
>
The error I keep getting is:

Traceback (most recent call last):
File "processor3.py", line 124, in ?
unzip(infolder)
File "processor3.py", line 53, in unzip
The error says that you are trying to seek 22 bytes backwards from the
end of a file that you presume is a zip file, and this is deemed to be
invalid. Hypotheses: (1) zipfile.py is buggy (2) your file is less
than 22 bytes long. Let's park hypothesis 1 for the moment. Insert the
following code before the call to zipfile.ZipFile:

print "trying to unzip %r whose size is %d bytes" \
% (one, os.stat(one).st_size)

and tell us your conclusions.
zfile = zipfile.ZipFile(one,'r')
File "/usr/lib/python2.4/zipfile.py", line 210, in __init__
self._GetContents()
File "/usr/lib/python2.4/zipfile.py", line 230, in _GetContents
self._RealGetContents()
File "/usr/lib/python2.4/zipfile.py", line 240, in _RealGetContents
endrec = _EndRecData(fp)
File "/usr/lib/python2.4/zipfile.py", line 83, in _EndRecData
fpin.seek(-22, 2) # Assume no archive comment.
IOError: [Errno 22] Invalid argument
P.S. Printing the contents of filelist immediately after it's been
created might be a good idea. You say "pick the zipped files" but the
only condition I see is a test using os.path.isdir.

HTH,
John
Jun 27 '08 #1
1 2164
jwesonga wrote:
I've added the line to the script, added a zipped file into the
folder. I've made sure the file exists. The error is now this:
Please get some clues:
(1) Don't reply off-list unless specifically invited.
(2) Don't top-post.
(3) Do read and try to understand *all* of each reply that you get ...
e.g. """
P.S. Printing the contents of filelist immediately after it's been
created might be a good idea. You say "pick the zipped files" but the
only condition I see is a test using os.path.isdir.
"""

(4) Do read and try to understand the output from your own script, e.g.
>
[jwesonga@web38 processor_files]$ python2.4 processor3.py
trying to unzip '/home/jwesonga/received/log.txt' whose size is 752
bytes
Doesn't that tell you anything? Like you are trying to unzip your own
logfile??

Traceback (most recent call last):
File "processor3.py", line 125, in ?
unzip(infolder)
File "processor3.py", line 54, in unzip
zfile = zipfile.ZipFile(one,'r')
File "/usr/lib/python2.4/zipfile.py", line 210, in __init__
self._GetContents()
File "/usr/lib/python2.4/zipfile.py", line 230, in _GetContents
self._RealGetContents()
File "/usr/lib/python2.4/zipfile.py", line 242, in _RealGetContents
raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file

This is strange because I can see the zipped file inside the folder /
home/jwesonga/received what could be the problem?

On Jun 4, 2:45 pm, John Machin <sjmac...@lexicon.netwrote:
>On Jun 4, 8:06 pm, jwesonga <crazylun...@gmail.comwrote:
>>Hi,
I have a python script that supposed to go through a folder, pick the
zipped files, unzip them and process the data inside. I'm not sure
where i'm going wrong with this script because it all seems correct:
Nothing is ever as it seems. Let's try to work backwards from the
error message ... and we don't need your magnificent script, just the
traceback will do for now, so:

[ big snip]
>>The error I keep getting is:
Traceback (most recent call last):
File "processor3.py", line 124, in ?
unzip(infolder)
File "processor3.py", line 53, in unzip
The error says that you are trying to seek 22 bytes backwards from the
end of a file that you presume is a zip file, and this is deemed to be
invalid. Hypotheses: (1) zipfile.py is buggy (2) your file is less
than 22 bytes long. Let's park hypothesis 1 for the moment. Insert the
following code before the call to zipfile.ZipFile:

print "trying to unzip %r whose size is %d bytes" \
% (one, os.stat(one).st_size)

and tell us your conclusions.
>> zfile = zipfile.ZipFile(one,'r')
File "/usr/lib/python2.4/zipfile.py", line 210, in __init__
self._GetContents()
File "/usr/lib/python2.4/zipfile.py", line 230, in _GetContents
self._RealGetContents()
File "/usr/lib/python2.4/zipfile.py", line 240, in _RealGetContents
endrec = _EndRecData(fp)
File "/usr/lib/python2.4/zipfile.py", line 83, in _EndRecData
fpin.seek(-22, 2) # Assume no archive comment.
IOError: [Errno 22] Invalid argument
P.S. Printing the contents of filelist immediately after it's been
created might be a good idea. You say "pick the zipped files" but the
only condition I see is a test using os.path.isdir.

HTH,
John


Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LC | last post by:
Hi, I'm having a problem using the zipfile module in Windows 2000 sp4. When I use it to zip a small file it works fine, but large file doesnt. Here's the error msg i get......
2
by: stewart.midwinter | last post by:
I've been experimenting with the python zipfile module, and have run into a snag. I'm able to create a new zipfile with the module's ZipFile class and add files to it. After closing the file,...
5
by: Waguy | last post by:
Hi all, I am new to python and want to create a process to unzip large numbers of zip files I get from a SOAP application. The files all have a ZIP extention and can be unzipped using WinZip. ...
11
by: Hari Sekhon | last post by:
I do import zipfile zip=zipfile.ZipFile('d:\somepath\cdimage.zip') zip.namelist() then either of the two: A) file('someimage.iso','w').write(zip.read('someimage.iso'))
1
by: Ritesh Raj Sarraf | last post by:
Hi, I've got a problem here. def compress_the_file(zip_file_name, files_to_compress, sSourceDir): """ Condenses all the files into one single file for easy transfer """ try:
5
by: OriginalBrownster | last post by:
This will probably sound like a very dumb question. I am trying to zip some files within a directory. I want to zip all the files within a directory called "temp" and have the zip archive...
8
by: =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B | last post by:
I made a C/S network program, the client receive the zip file from the server, and read the data into a variable. how could I process the zipfile directly without saving it into file. In the...
3
by: Larry Bates | last post by:
I'm trying to learn about subclassing new style classes and the first project I went to do needs to subclass zipfile to add some methods. Why does this: import zipfile class...
5
by: Neil Crighton | last post by:
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for extracted text-encoded files, removing all instances...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.