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


Groups > comp.lang.python > #8639

Re: urllib, urlretrieve method, how to get headers?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kushal.kumaran@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'server:': 0.07; 'question:': 0.09; 'subject:method': 0.09; 'wrote:': 0.15; '(unix)': 0.16; '225': 0.16; 'connection:': 0.16; 'f.read()': 0.16; 'parts?': 0.16; 'subject:headers': 0.16; 'subject:urllib': 0.16; 'url:amd64': 0.16; 'url:debian': 0.16; 'cc:addr:python- list': 0.16; 'pm,': 0.16; 'bytes': 0.19; 'received:74.125.82.44': 0.19; 'received:mail-ww0-f44.google.com': 0.19; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'date:': 0.25; 'specified': 0.25; 'sender:addr:gmail.com': 0.26; 'fri,': 0.28; 'skip:" 30': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.30; 'gmt': 0.30; 'sun,': 0.30; 'subject:?': 0.31; 'print': 0.32; "skip:' 10": 0.32; 'headers': 0.32; 'page': 0.36; 'http': 0.37; 'but': 0.37; 'another': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'data': 0.39; 'received:74.125.82': 0.39; 'header': 0.40; 'format': 0.40; 'received:74.125': 0.40; '500': 0.61; 'full': 0.63; 'here:': 0.64; 'url:0': 0.69; "'range'": 0.84; 'requests.': 0.84; 'url:35': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=q1OKdnmomRUHnKyluQSpbnPrWo/UQwvBI+qxrM94bj0=; b=rT0fHLCVlLsQVyGXJilOvvkIa1ViawMy6tfYG2tCf5CpiizAumOJkoW0C1p+YtnW1x +FhkuMGdxnL+1JlTQhrMhFvphAL9AneGhRJpdrcTuIx3iKwLzSiq1Z6tSXm73DZjTf6d 1npydPka+f1tfePyTLTObSqy+KOZuHUCjASIQ=
MIME-Version 1.0
Sender kushal.kumaran@gmail.com
In-Reply-To <BANLkTinwir_KKhmq1EdQGWLvxLQ4v3CULQ@mail.gmail.com>
References <mailman.536.1309503827.1164.python-list@python.org> <iujtq4$srp$1@solani.org> <BANLkTinNLdfVRt+ExwFaMzM=JAcrJ4NqKQ@mail.gmail.com> <BANLkTi=PeQd_9W1nY4aTpp5gN4sLEWWisQ@mail.gmail.com> <BANLkTinwir_KKhmq1EdQGWLvxLQ4v3CULQ@mail.gmail.com>
From Kushal Kumaran <kushal.kumaran+python@gmail.com>
Date Fri, 1 Jul 2011 22:31:42 +0530
X-Google-Sender-Auth OX_wcxQcmFI35totF7VAGNa-XtU
Subject Re: urllib, urlretrieve method, how to get headers?
To Даниил Рыжков <daniil.re@gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc 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.544.1309539723.1164.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1309539723 news.xs4all.nl 21874 [2001:888:2000:d::a6]:42152
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8639

Show key headers only | View raw


On Fri, Jul 1, 2011 at 2:23 PM, Даниил Рыжков <daniil.re@gmail.com> wrote:
> Hello again!
> Another question: urlopen() reads full file's content, but how can I
> get page by small parts?
>

Set the Range header for HTTP requests.  The format is specified here:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.  Note
that web servers are not *required* to support this header.

In [10]: req = urllib2.Request('http://cdimage.debian.org/debian-cd/6.0.2.1/amd64/iso-cd/debian-6.0.2.1-amd64-CD-1.iso',
headers = { 'Range' : 'bytes=0-499' })

In [11]: f = urllib2.urlopen(req)

In [12]: data = f.read()

In [13]: len(data)
Out[13]: 500

In [14]: print f.headers
Date: Fri, 01 Jul 2011 16:59:39 GMT
Server: Apache/2.2.14 (Unix)
Last-Modified: Sun, 26 Jun 2011 16:54:45 GMT
ETag: "ebff2f-28700000-4a6a04ab27f10"
Accept-Ranges: bytes
Content-Length: 500
Age: 225
Content-Range: bytes 0-499/678428672
Connection: close
Content-Type: application/octet-stream


-- 
regards,
kushal

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


Thread

urllib, urlretrieve method, how to get headers? Даниил Рыжков <daniil.re@gmail.com> - 2011-07-01 18:03 +1100
  Re: urllib, urlretrieve method, how to get headers? Peter Otten <__peter__@web.de> - 2011-07-01 09:43 +0200
    Re: urllib, urlretrieve method, how to get headers? Даниил Рыжков <daniil.re@gmail.com> - 2011-07-01 19:26 +1100
    Re: urllib, urlretrieve method, how to get headers? Даниил Рыжков <daniil.re@gmail.com> - 2011-07-01 19:53 +1100
    Re: urllib, urlretrieve method, how to get headers? Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-07-01 22:31 +0530
    Re: urllib, urlretrieve method, how to get headers? Chris Rebert <clp2@rebertia.com> - 2011-07-01 10:02 -0700
    Re: urllib, urlretrieve method, how to get headers? Даниил Рыжков <daniil.re@gmail.com> - 2011-07-02 11:47 +1100

csiph-web