title: Python - Using Windows hosts file when using Python Requests / Use predefined IP Address without making a DNS request
body: <p>I am trying to use Python requests to make a HTTP GET request to a domain, without using urllib3/httplib.HTTPConnection to perform a DNS request for the domain. I set the domain in the Windows hosts file, but Python requests appears to override this, so I need to define the DNS resolution for the domain in the script.</p>
  
  <p>I want to script to bypass the dns request so I can set the IP address. In the example below I've set this to 45.22.67.8, and I will change this to my public IP address later. </p>
  
  <p>I tried using this 'monkey patching' technique but it doesn't work. Requests doesn't generate a DNS request in Wireshark, but it also doesn't connect to the HTTP server. </p>
  
  <pre><code>    import socket
      import requests
      from requests.packages.urllib3.connection import HTTPConnection
  
      socket.getaddrinfo = '45.22.67.8'       
  
       url = "http://www.randomdomain.com"
       requests.get(url, timeout=10)
  </code></pre>
  
  <p>Error</p>
  
  <p>'str' object is not callable</p>
  
  <p>Thanks!</p>
  
  <p>Edit: just updated the code in my example. All I want to do is override future http connections to trick the http packets to go to a different destination IP. </p>