title: urllib2.urlopen can't look up a hostname using my normal DNS server; dig etc. can
body: <p>I'm trying to troubleshoot a problem with urllib2.urlopen. It can't seem to make use of my regular DNS server. Below is the result of several attempts to open various URLs, first using Google public DNS (8.8.8.8) and second using my router. gridley is defined in my /etc/hosts file.</p>
  
  <pre><code>Python 2.7.2 (default, Jun 29 2011, 11:17:09) 
  [GCC 4.6.1] on linux2
  &gt;&gt;&gt; import urllib2
  &gt;&gt;&gt; urllib2.urlopen("http://gridley")
  &lt;addinfourl at 158490988 whose fp = &lt;socket._fileobject object at 0xb745f7ec&gt;&gt;
  &gt;&gt;&gt; urllib2.urlopen("http://google.com")
  &lt;addinfourl at 158492204 whose fp = &lt;socket._fileobject object at 0x971842c&gt;&gt;
  
  Python 2.7.2 (default, Jun 29 2011, 11:17:09) 
  [GCC 4.6.1] on linux2
  &gt;&gt;&gt; import urllib2
  &gt;&gt;&gt; urllib2.urlopen("http://gridley")
  &lt;addinfourl at 154808684 whose fp = &lt;socket._fileobject object at 0xb73997ec&gt;&gt;
  &gt;&gt;&gt; urllib2.urlopen("http://google.com")
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
      return _opener.open(url, data, timeout)
    File "/usr/lib/python2.7/urllib2.py", line 394, in open
      response = self._open(req, data)
    File "/usr/lib/python2.7/urllib2.py", line 412, in _open
      '_open', req)
    File "/usr/lib/python2.7/urllib2.py", line 372, in _call_chain
      result = func(*args)
    File "/usr/lib/python2.7/urllib2.py", line 1199, in http_open
      return self.do_open(httplib.HTTPConnection, req)
    File "/usr/lib/python2.7/urllib2.py", line 1174, in do_open
      raise URLError(err)
  urllib2.URLError: &lt;urlopen error [Errno -5] No address associated with hostname
  </code></pre>
  
  <p>However, querying google.com with dig shows that it definitely should work:</p>
  
  <pre><code>; &lt;&lt;&gt;&gt; DiG 9.8.1 &lt;&lt;&gt;&gt; google.com
  ;; global options: +cmd
  ;; Got answer:
  ;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 44377
  ;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0
  
  ;; QUESTION SECTION:
  ;google.com.            IN  A
  
  ;; ANSWER SECTION:
  google.com.     190 IN  A   74.125.225.83
  google.com.     190 IN  A   74.125.225.81
  google.com.     190 IN  A   74.125.225.82
  google.com.     190 IN  A   74.125.225.80
  google.com.     190 IN  A   74.125.225.84
  
  ;; Query time: 23 msec
  ;; SERVER: 192.168.7.254#53(192.168.7.254)
  ;; WHEN: Sun Sep 18 19:46:12 2011
  ;; MSG SIZE  rcvd: 108
  </code></pre>
  
  <p>IPv6 caused some other problems, but it's completely off now, so that can't be it. What the heck is going on?</p>