Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'wed,': 0.03; 'https': 0.07; 'urllib2': 0.07; 'user-agent:': 0.07; 'python': 0.08; 'hosts': 0.09; 'subject:DNS': 0.09; 'unix,': 0.09; 'linux': 0.11; '>>>': 0.12; 'am,': 0.14; 'received:209.85.214.174': 0.14; 'received:mail-iw0-f174.google.com': 0.14; 'wrote:': 0.14; 'angelico': 0.16; "computer's": 0.16; 'conn': 0.16; 'connection:': 0.16; 'curious,': 0.16; 'f.read()': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'meanwhile': 0.16; 'header :In-Reply-To:1': 0.21; 'trying': 0.23; "what's": 0.23; 'code': 0.24; 'subject:Question': 0.25; 'script': 0.27; 'message- id:@mail.gmail.com': 0.28; 'skip:p 30': 0.28; 'problem': 0.28; 'received:209.85.214': 0.28; 'import': 0.29; 'server': 0.29; 'host': 0.29; 'apply': 0.32; 'file.': 0.32; 'to:addr:python-list': 0.33; 'chris': 0.34; 'source': 0.34; 'dns': 0.35; 'using': 0.35; 'selection': 0.36; 'running': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'http': 0.37; 'case': 0.37; 'could': 0.38; 'but': 0.38; 'returning': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'received:209': 0.39; 'add': 0.39; 'to:addr:python.org': 0.39; 'header': 0.40; 'plain': 0.40; 'address': 0.62; 'respect': 0.65; 'domains': 0.67; '2.7.1': 0.84; 'beside': 0.84; 'reports:': 0.84; 'can\x92t': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=DLA0FLQAXEdGvlj2duG6He1BZez5PRNUy5JLpYOrSUM=; b=QYiC52raYrGEzpZ9Y4Fx0JCBW5T/R6gvhzY+ff7eKgR84hkHHQ4Y1fIpsX4bypGMgs vv3fuSRf+7JahBhQc9XlsHGxJVz8/oXn5cmduUiszL6TbyXO48HLStu3tSf/WYPCigiy yD/0RUPoTF8OTjWRbyiBGLbxPDrssd4zjeshY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=gwipCBuUMG1Q+jKMF8VQDWUitA6E0v5Bf+F1kDBLxQzY/gPHKrlO11B+Qs1kOj8O3i 3pl7p6hOnV17d9hVk1zX0bZlz5YLZaYL+WJIgDtVMd7p0FhDTcLB+lCSCP6DIEvU4JQ/ w1hBpRdZLThJ5OJ/abCn6tChOenUw/p1628j0= MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 15 Jun 2011 10:43:23 +1000 Subject: Re: Question regarding DNS resolution in urllib2 From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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: 38 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308098606 news.xs4all.nl 49177 [::ffff:82.94.164.166]:40852 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7656 On Wed, Jun 15, 2011 at 4:34 AM, saurabh verma wro= te: > hi , > > I trying to use urllib2 in my script , but the problem is lets say a doma= ins resolves to multiple IPs , If the URL is served by plain http , I can a= dd =93Host: domain=94 header and check whether all IPs are returning proper= responses or not , but in case of https , I have to trust on my local mach= ines dns resolver and I can=92t apply host header in the request . Regarding Host: headers, experimentation showed that urllib2 did indeed send one (I tested using Python 2.7.1 on Windows, talking to a snooping HTTPS server running on a Linux box beside me - source code available if you're curious, but it's not Python). >>> import urllib2 >>> req=3Durllib2.Request(url=3D'https://mirlemont/') >>> f=3Durllib2.urlopen(req) >>> f.read() 'Hello, world!' Meanwhile the snoop server reports: conn =3D Protocols.HTTP.Server.Request("GET" "/") GET / HTTP/1.1 Accept-Encoding: identity Host: mirlemont Connection: close User-Agent: Python-urllib/2.7 (Yes, my computer's name is Mirlemont. What's yours'? :) ) You could control the selection of IP address using a hosts file. In Unix, that's /etc/hosts; in Windows, c:\windows\system32\drivers\etc\hosts; in OS/2, c:\mptn\etc\hosts; etc. The urllib2 resolver should respect that. Chris Angelico