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


Groups > comp.lang.python > #7656 > unrolled thread

Re: Question regarding DNS resolution in urllib2

Started byChris Angelico <rosuav@gmail.com>
First post2011-06-15 10:43 +1000
Last post2011-06-15 10:43 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Question regarding DNS resolution in urllib2 Chris Angelico <rosuav@gmail.com> - 2011-06-15 10:43 +1000

#7656 — Re: Question regarding DNS resolution in urllib2

FromChris Angelico <rosuav@gmail.com>
Date2011-06-15 10:43 +1000
SubjectRe: Question regarding DNS resolution in urllib2
Message-ID<mailman.246.1308098605.11593.python-list@python.org>
On Wed, Jun 15, 2011 at 4:34 AM, saurabh verma <nitw.saurabh@gmail.com> wrote:
> hi ,
>
> I trying to use urllib2 in my script , but the problem is lets say a domains resolves to multiple IPs , If the URL is served by plain http , I can add “Host: domain” header and check whether all IPs are returning proper responses or not , but in case of https , I have to trust on my local machines dns resolver and I can’t 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=urllib2.Request(url='https://mirlemont/')
>>> f=urllib2.urlopen(req)
>>> f.read()
'Hello, world!'

Meanwhile the snoop server reports:

conn = 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web