title: Python: How can I use urllib or requests modules from a corporate domain (firewall, proxy, cntlm etc)
body: <p>I am trying to do the following:</p>
  
  <pre><code>from urllib.request import urlopen
  data = urlopen("https://www.duolingo.com/users/SaifullahS6").read()
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>URLError: &lt;urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond&gt;
  </code></pre>
  
  <p>Similarly, when I try this:</p>
  
  <pre><code>import requests
  session = requests.Session()
  data = {"login": "SaifullahS6", "password": "mypassword"}
  req = requests.Request('POST', "https://www.duolingo.com/login", data=data,         
  cookies=session.cookies)
  prepped=req.prepare()
  returned = session.send(prepped)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>ConnectionError: HTTPSConnectionPool(host='www.duolingo.com', port=443): Max retries exceeded with url: /login (Caused by NewConnectionError('&lt;requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000000000E6948D0&gt;: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))
  </code></pre>
  
  <p>I am not sure how to give details of my internet connection.</p>
  
  <ul>
  <li>I'm at work and I know we have a corporate proxy.</li>
  <li>We have Windows Firewall turned on, but i have checked that python and pythonw are ticked in the "Domain" column of the control panel for allowing a program through the firewall.</li>
  <li>When I ping google.co.uk from a command shell, all four requests time out, but I can access it from a browser.</li>
  <li>In the Internet Options control panel, I click on the Connections tab and then LAN settings, and I have "Automatically detect settings" turned on, and also "Use a proxy server for your LAN", "Address" is "localhost" and "Port" is 3128. This is cntlm. I set it up once to do download python packages, and it appears to still be active because I have just managed to update one of my packages.</li>
  </ul>
  
  <p>I don't even need a direct answer to my question; at this point I'll just  settle for some clarity on what is actually going on behind the scenes. Any help much appreciated!</p>