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; 'indicates': 0.09; 'interpreting': 0.09; '>>>': 0.12; 'wrote:': 0.14; '*always*': 0.16; "b''": 0.16; 'from:addr:awilliam': 0.16; 'from:addr:whitemice.org': 0.16; 'from:name:adam tauno williams': 0.16; 'py3': 0.16; 'read()': 0.16; 'received:72.14.190': 0.16; 'received:72.14.190.87': 0.16; 'received:mail.wmmi.net': 0.16; 'received:wmmi.net': 0.16; 'reply-to:addr:awilliam': 0.16; 'reply- to:addr:whitemice.org': 0.16; 'x-mailer:evolution 2.30.1.2': 0.16; 'header:In-Reply-To:1': 0.21; 'thu,': 0.22; 'code': 0.24; 'function': 0.25; 'received:72.14': 0.26; "i'm": 0.27; 'all,': 0.30; 'someone': 0.33; 'to:addr:python-list': 0.33; 'there': 0.35; '-0700,': 0.35; 'skip:h 40': 0.35; 'useful': 0.37; 'response': 0.37; 'pretty': 0.37; 'subject:: ': 0.38; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'body': 0.61; 'response.': 0.68; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72 Subject: Re: HTTPConncetion - HEAD request From: Adam Tauno Williams To: python-list@python.org In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Organization: Whitemice Consulting Date: Fri, 17 Jun 2011 06:14:38 -0400 Mime-Version: 1.0 X-Mailer: Evolution 2.30.1.2 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: awilliam@whitemice.org 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: 18 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308304747 news.xs4all.nl 49183 [::ffff:82.94.164.166]:57750 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7815 On Thu, 2011-06-16 at 15:43 -0700, gervaz wrote: > Hi all, can someone tell me why the read() function in the following > py3 code returns b'' > >>> h = http.client.HTTPConnection("www.twitter.com") > >>> h.connect() > >>> h.request("HEAD", "/", "HTTP 1.0") > >>> r = h.getresponse() > >>> r.read() > b'' Because there is no body in a HEAD request. What is useful are the Content-Type, Content-Length, and etag headers. Is r.getcode() == 200? That indicates a successful response; you *always* much check the response code before interpreting the response. Also I'm pretty sure that "HTTP 1.0" is wrong.