title: Python urllib over TOR?
body: <p>Sample code:</p>
  
  <pre><code>#!/usr/bin/python
  import socks
  import socket
  import urllib2
  
  socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, "127.0.0.1", 9050, True)
  socket.socket = socks.socksocket
  
  print urllib2.urlopen("http://almien.co.uk/m/tools/net/ip/").read()
  </code></pre>
  
  <p>TOR is running a SOCKS proxy on port 9050 (its default).  The request goes through TOR, surfacing at an IP address other than my own.  However, TOR console gives the warning:</p>
  
  <blockquote>
    <p>"Feb 28 22:44:26.233 [warn] Your
    application (using socks4 to port 80)
    is giving Tor only an IP address.
    Applications that do DNS resolves
    themselves may leak information.
    Consider using Socks4A (e.g. via
    privoxy or socat) instead. For more
    information, please see
    <a href="https://wiki.torproject.org/TheOnionRouter/TorFAQ#SOCKSAndDNS">https://wiki.torproject.org/TheOnionRouter/TorFAQ#SOCKSAndDNS</a>."</p>
  </blockquote>
  
  <p>i.e. DNS lookups aren't going through the proxy.  But that's what the 4th parameter to setdefaultproxy is supposed to do, right?  </p>
  
  <p>From <a href="http://socksipy.sourceforge.net/readme.txt">http://socksipy.sourceforge.net/readme.txt</a>:</p>
  
  <blockquote>
    <p>setproxy(proxytype, addr[, port[, rdns[, username[, password]]]])</p>
    
    <p>rdns - This is a boolean flag than
    modifies the behavior regarding DNS
    resolving. If it is set to True, DNS
    resolving will be preformed remotely,
    on the server.</p>
  </blockquote>
  
  <p>Same effect with both PROXY_TYPE_SOCKS4 and PROXY_TYPE_SOCKS5 selected.</p>
  
  <p>It can't be a local DNS cache (if urllib2 even supports that) because it happens when I change the URL to a domain that this computer has never visited before.</p>