Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:file': 0.07; "'rb')": 0.09; 'here?': 0.09; 'subject:Posting': 0.09; 'cc:addr :python-list': 0.10; 'thu,': 0.15; 'big,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inclined': 0.16; 'iteration': 0.16; 'skip:g 50': 0.16; 'subject:image': 0.16; 'subject:server': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'am,': 0.23; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'paul': 0.24; 'plain': 0.27; 'message-id:@mail.gmail.com': 0.28; 'once.': 0.29; "i'd": 0.31; 'subject:?': 0.34; 'file': 0.34; 'received:google.com': 0.34; 'text.': 0.35; "isn't": 0.35; 'too': 0.36; 'subject:: ': 0.37; 'sure': 0.40; 'avoid': 0.61; 'situation': 0.67; 'blob': 0.84; 'chrisa': 0.84; 'to:none': 0.90 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Cd/2rUV4rTCkYIbZJv4SKAcwd+Y/zolHMb7j8pSni6k=; b=COkao3+Fzhi829cclEa2VcydmegLo/KlQYUU/6m+NteaBt7VetcbwZLS1mFQ54Mywy Jqsg6kCii2HK7IK59jQZIWjo5twXthULZT0N44MQ3yB/ZyjtweysARHUqBjPktUXomMn NIoWpXVjwWFV8FJDUH974Cl0Vz70pomPaJGS+q7w5nUQQ/rr81x+kj3XooDELgaBYlzV R9dxHVD1UOAqepRIiVxBVzUl4XykCPRstSkB7dEJ0j2nAsop59G2rLZ6ktCjKOxrs8rH TMTMrIiFZdA3DdSPu+p0mvMyhvZl7jte0bLQTQUCavhE0qMKRzhI28dLPvcEXfzbzfEP fY8Q== MIME-Version: 1.0 X-Received: by 10.50.143.104 with SMTP id sd8mr38667693igb.14.1434587006761; Wed, 17 Jun 2015 17:23:26 -0700 (PDT) In-Reply-To: <59756062-6632-46b4-a92c-aa3a260718a7@googlegroups.com> References: <59756062-6632-46b4-a92c-aa3a260718a7@googlegroups.com> Date: Thu, 18 Jun 2015 10:23:26 +1000 Subject: Re: Posting gzip'd image file - server says Malformed Upload? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434587009 news.xs4all.nl 2881 [2001:888:2000:d::a6]:42642 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3524 X-Received-Body-CRC: 2755934881 Xref: csiph.com comp.lang.python:92797 On Thu, Jun 18, 2015 at 7:55 AM, Paul Hubert wrote: > f_in = open(dafile, 'rb') > f_out = gzip.open('/Users/Paul/Desktop/scripts/pic.jpg.gz', 'wb') > f_out.writelines(f_in) > f_out.close() > f_in.close() Are you sure you want iteration and writelines() here? I would be inclined to avoid those for any situation that isn't plain text. If the file isn't too big, I'd just read it all in a single blob and then write it all out at once. ChrisA