ipython-minibook icon indicating copy to clipboard operation
ipython-minibook copied to clipboard

code in chapter 2 downloads a bad zipfile

Open mmagnuski opened this issue 9 years ago • 2 comments

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! :+1: :+1: :+1:

mmagnuski avatar Mar 01 '15 13:03 mmagnuski