Python: HTTPConnectionPool(host='%s', port=80):
<pre><code>import requests
import urllib3
from time import sleep
from sys import argv
script, filename = argv
http = urllib3.PoolManager()

datafile = open('datafile.txt','w')
crawl = ""

with open(filename) as f:
mylist = f.read().splitlines()

def crawlling(x):
    for i in mylist:
        domain = ("http://" + "%s") % i
        crawl = http.request('GET','%s',preload_content=False) % domain
        for crawl in crawl.stream(32):
            print crawl
            sleep(10)
            crawl.release_conn()
            datafile.write(crawl.status)
            datafile.write('&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\n')
            datafile.write(crawl.data)
            datafile.close()
return x


crawlling(crawl)

_______________________________________________________________________
Extract of domain.txt file:
fjarorojo.info
buscadordeproductos.com
</code></pre>

<p>I'm new to python so bear with me: I'm trying to trying get content from URL but it's throwing error. Further, it's working fine in browser.
Object of script is to get the data from domain.txt file and iterate over it and fetch the content and save it in file.</p>

<pre><code>Getting this error: 
  raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='%s',
port=80):     Max retries exceeded with url: / (Caused by 
NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 
0x7ff45e4f9cd0&gt;: Failed to establish a new connection: [Errno -2] Name or 
service not known',))
</code></pre>

<p>This line is the problem:</p>

<pre><code>crawl = http.request('GET','%s',preload_content=False) % domain
</code></pre>

<p>Right now you're trying to make a request to the domain <code>%s</code> which is not a valid domain, hence the error "Name or 
service not known".</p>

<p>It should be:</p>

<pre><code>crawl = http.request('GET', '%s' % domain, preload_content=False)
</code></pre>

<p>Or more simply:</p>

<pre><code>crawl = http.request('GET', domain, preload_content=False)
</code></pre>

<p>Also, unrelated to the error you posted, these lines will likely cause problems too:</p>

<pre><code>    for crawl in crawl.stream(32):
        print crawl
        sleep(10)
        crawl.release_conn() # &lt;--
</code></pre>

<p>You're releasing the connection in a loop, so the loop will fail to yield the expected results on the second iteration. Instead, you should only release the connection once you're done with the request. <a href="http://urllib3.readthedocs.io/en/latest/advanced-usage.html?highlight=stream#streaming-and-io" rel="nofollow">More details here</a>.</p>

python web-scraping python-requests urllib3