Error from zipfile

John Machin sjmachin at lexicon.net
Tue Jul 1 17:49:28 EDT 2008


On Jul 2, 1:38 am, "Wesley Brooks" <wesbro... at gmail.com> wrote:
> Dear Users,
>
> I'm having a problem when trying to move script from Linux to Windows.
> A zipfile opperation is failing with the message:
>
> "BadZipFile: File is not a zip file"
>
> I have a simple scripts that reads a zip file in the same way as any
> other file into a string, then sends it across to a network where it
> is saved as perusual into a file, then read in and processed by
> zipfile.

If "saved as per usual" means something like open('foo.zip',
'w').write(the_string) then this is highly likely to be your
problem.   Use 'wb'. Get into the habit of using the 'b' flag on
binary files in your scripts (whether reading or writing) and they'll
be much more portable.

Something to check: on the Linux side, do
   wc -l foo.zip
(that option's 'L'.lower()) to get the number of pseudo-lines in your
zip file, and compare the sizes of the file on Linux and Windows. What
do you see?

HTH,
John



More information about the Python-list mailing list