Skip to content

code in chapter 2 downloads a bad zipfile #3

Description

@mmagnuski

Hi Cyrille,

In chapter 2 there is a code that downloads a facebook.zip file:

import urllib2, zipfile
url = 'http://ipython.rossant.net/'
filename = 'facebook.zip'

downloaded = urllib2.urlopen(url + filename)
with open(filename, 'wb') as f:
    f.write(downloaded.read())

For some reason the code does not download a valid zip file. Running the next part of code gives BadZipFile error:

with zipfile.ZipFile(filename) as zip:
    zip.extractall('.')

the traceback:

---------------------------------------------------------------------------
BadZipfile                                Traceback (most recent call last)
<ipython-input-10-091bb6db8a0d> in <module>()
----> 1 with zipfile.ZipFile(filename) as zip:
      2     zip.extractall('.')

D:\Python\Anaconda\lib\zipfile.pyc in __init__(self, file, mode, compression, allowZip64)
    768         try:
    769             if key == 'r':
--> 770                 self._RealGetContents()
    771             elif key == 'w':
    772                 # set the modified flag so central directory gets written

D:\Python\Anaconda\lib\zipfile.pyc in _RealGetContents(self)
    809             raise BadZipfile("File is not a zip file")
    810         if not endrec:
--> 811             raise BadZipfile, "File is not a zip file"
    812         if self.debug > 1:
    813             print endrec

BadZipfile: File is not a zip file

At least this is what happens on my windows 8 machine.
Downloading the file by hand (in Chorme) works well (no errors in the unzipping code).

I have a 64-bit windows and 32-bit python (psychopy does not work with 64-bit python):

Python 2.7.7 :: Anaconda 2.0.1 (32-bit)

Do you think this could be the source of this problem?

BTW: thanks for a great book! 👍 👍 👍

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions