Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10329

reading zipfile; problem using raw buffer

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <fred.sells@adventistcare.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'subject:using': 0.04; 'snippet': 0.07; 'exception.': 0.09; 'skip:" 60': 0.09; '"bad': 0.16; '"r",': 0.16; "'w')": 0.16; 'f.read()': 0.16; 'guessing': 0.16; 'somewhere?': 0.16; 'subject:raw': 0.16; 'tmp': 0.16; 'def': 0.16; 'aug': 0.19; 'subject:problem': 0.19; 'wrote': 0.21; '(most': 0.21; 'header:In- Reply-To:1': 0.22; 'fine,': 0.23; 'traceback': 0.25; "i'm": 0.27; 'raise': 0.28; 'mode': 0.28; 'skip:" 30': 0.28; 'bit': 0.28; 'print': 0.32; 'break': 0.33; "what's": 0.33; 'to:addr:python- list': 0.34; 'last):': 0.35; 'charset:us-ascii': 0.36; 'file': 0.36; 'issue': 0.37; 'skip:z 20': 0.37; 'open': 0.37; 'some': 0.37; 'but': 0.37; 'received:192': 0.38; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'header': 0.40; 'skip:z 10': 0.40; 'batch': 0.68; 'subject: ': 0.73; 'isolate': 0.84; 'subject:; ': 0.91
X-MimeOLE Produced By Microsoft Exchange V6.5
Content-class urn:content-classes:message
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
Subject reading zipfile; problem using raw buffer
Date Tue, 26 Jul 2011 08:42:25 -0400
In-Reply-To <ab8b6e1f-f850-446b-aa34-47997974825d@d7g2000vbv.googlegroups.com>
X-MS-Has-Attach
X-MS-TNEF-Correlator
Thread-Topic reading zipfile; problem using raw buffer
Thread-Index AcxLEFgsnIZyRsd0RJ2WGCgjnrr+PAAf+GkQ
References <acaab166-32c1-43df-b1a4-e3b47c62be36@m10g2000yqd.googlegroups.com><08098816-0332-4ae2-a125-35418bac0da2@dp9g2000vbb.googlegroups.com> <ab8b6e1f-f850-446b-aa34-47997974825d@d7g2000vbv.googlegroups.com>
From "Sells, Fred" <fred.sells@adventistcare.org>
To <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1493.1311684149.1164.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1311684149 news.xs4all.nl 23976 [2001:888:2000:d::a6]:52065
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10329

Show key headers only | View raw


I'm tring to unzip a buffer that is uploaded to django/python.  I can
unzip the file in batch mode just fine, but when I get the buffer I get
a "BadZipfile exception.  I wrote this snippet to try to isolate the
issue but I don't understand what's going on.  I'm guessing that I'm
losing some header/trailer somewhere?

def unittestZipfile(filename):
    buffer = ''
    f = open(filename)
    for i in range(22):
        block = f.read()
        if len(block) == 0: 
            break
        else:
            buffer += block

    print len(buffer)
    tmp = open('tmp.zip', 'w')
    tmp.write(buffer)
    tmp.close()
    zf = zipfile.ZipFile('tmp.zip')
    print dir(zf)
    for name in zf.namelist():
        print name
        print zf.read(name)
____________________________________________________________
2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
Traceback (most recent call last):
  File
"C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py",
line 162, in <module>
    unittestZipfile('wk1live7.8to7.11.zip')    
  File
"C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py",
line 146, in unittestZipfile
    print zf.read(name)
  File "C:\alltools\python26\lib\zipfile.py", line 837, in read
    return self.open(name, "r", pwd).read()
  File "C:\alltools\python26\lib\zipfile.py", line 867, in open
    raise BadZipfile, "Bad magic number for file header"
zipfile.BadZipfile: Bad magic number for file header

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Pipe in the "return" statement Archard Lias <archardlias@googlemail.com> - 2011-07-25 05:00 -0700
  Re: Pipe in the "return" statement Ian Collins <ian-news@hotmail.com> - 2011-07-26 00:03 +1200
    Re: Pipe in the "return" statement Archard Lias <archardlias@googlemail.com> - 2011-07-25 07:16 -0700
      Re: Pipe in the "return" statement Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6@myhashismyemail.com> - 2011-07-25 10:31 -0400
        Re: Pipe in the "return" statement Ethan Furman <ethan@stoneleaf.us> - 2011-07-25 13:07 -0700
          Re: Pipe in the "return" statement Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-07-28 08:26 +0200
      Re: Pipe in the "return" statement Oliver Bestwalter <oliver@bestwalter.de> - 2011-07-25 16:35 +0200
        Re: Pipe in the "return" statement Archard Lias <archardlias@googlemail.com> - 2011-07-25 08:05 -0700
      Re: Pipe in the "return" statement John Gordon <gordon@panix.com> - 2011-07-25 14:39 +0000
        Re: Pipe in the "return" statement Archard Lias <archardlias@googlemail.com> - 2011-07-25 08:06 -0700
      Re: Pipe in the "return" statement gwowen <gwowen@gmail.com> - 2011-07-25 07:42 -0700
  Re: Pipe in the "return" statement Christian Heimes <lists@cheimes.de> - 2011-07-25 14:33 +0200
    Re: Pipe in the "return" statement Archard Lias <archardlias@googlemail.com> - 2011-07-25 08:28 -0700
      Re: Pipe in the "return" statement Christian Heimes <lists@cheimes.de> - 2011-07-25 18:11 +0200
        Re: Pipe in the "return" statement Archard Lias <archardlias@googlemail.com> - 2011-07-25 09:30 -0700
  Re: Pipe in the "return" statement TonyO <guinness.tony@gmail.com> - 2011-07-25 05:52 -0700
    Re: Pipe in the "return" statement gwowen <gwowen@gmail.com> - 2011-07-25 06:00 -0700
    Re: Pipe in the "return" statement red floyd <redfloyd@gmail.com> - 2011-07-25 14:04 -0700
      reading  zipfile; problem using raw buffer "Sells, Fred" <fred.sells@adventistcare.org> - 2011-07-26 08:42 -0400
        Re: reading  zipfile; problem using raw buffer Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6@myhashismyemail.com> - 2011-07-26 08:49 -0400
      Re: reading  zipfile; problem using raw buffer Peter Otten <__peter__@web.de> - 2011-07-26 15:04 +0200
      RE: reading  zipfile; problem using raw buffer "Sells, Fred" <fred.sells@adventistcare.org> - 2011-07-26 11:22 -0400

csiph-web