Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'exits': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.12; 'examples': 0.12; 'wrote:': 0.14; '200)': 0.16; 'received:forthnet.gr': 0.16; 'code.': 0.22; 'fri,': 0.23; '(e.g.': 0.26; 'script': 0.27; 'testing': 0.27; 'class': 0.29; 'implement': 0.30; 'none,': 0.30; 'headers': 0.32; 'header:X -Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'header :User-Agent:1': 0.35; 'quite': 0.36; 'response': 0.37; 'received:org': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'header :Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'your': 0.60; 'forget': 0.61; 'received:62': 0.68 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Elias Fotinis" Subject: Re: HTTPConncetion - HEAD request Date: Sun, 19 Jun 2011 16:21:32 +0300 References: <38df1fae-a7bd-43c3-8b3d-b8d685af4b9f@fp11g2000vbb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 62.1.231.136.dsl.dyn.forthnet.gr User-Agent: Opera Mail/11.11 (Win32) X-Antivirus: avast! (VPS 110618-1, 06/19/2011), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 20 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308489706 news.xs4all.nl 49174 [::ffff:82.94.164.166]:43355 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7952 On Fri, 17 Jun 2011 20:53:39 +0300, gervaz wrote: > I decided to implement this solution: > > class HeadRequest(urllib.request.Request): > def get_method(self): > return "HEAD" > > Now I download the url using: > > r = HeadRequest(url, None, self.headers) > c = urllib.request.urlopen(r) > > but I don't know how to retrieve the request status (e.g. 200) as in > the previous examples with a different implementation... Use c.getcode() to get the response code. When you're testing interactively, you might find printing the headers with "print c.headers" quite handy. Don't forget to close the response (c.close()) when your script exits its experimental state.