Forums

NewConnectionError('<urllib3.connection.HTTPConnection Failed to establish a new connection: [Errno 101] Network is unreachable',)

Hello. I am having some difficulties with a web app that uses urllib3 to access content on a whitelisted site (swapi.co). The request is made using the following:

try:
    http = urllib3.PoolManager(
        cert_reqs='CERT_REQUIRED',
        ca_certs=certifi.where())
    r = http.request('GET', url)
    content = r.data
except urllib3.exceptions.HTTPError:
    return
if content:
    x = json.loads(content)
    return x

The first (1) error I got was when using the code with the url as 'https://swapi.co/api/people/'. After googling around, I tried removing the https:// and the received the second (2) error. The error is similar to the one mentioned here 'https://www.pythonanywhere.com/forums/topic/11231/#id_post_42173'. What can I do to fix this error. Thanks in advance.

(1) <p>2018-01-20 19:54:20,790: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('yyyyyy: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /api/people/10</p>

yyyyyy should be replaced with ----> urllib3.connection.VerifiedHTTPSConnection object

(2) <p>2018-01-20 20:44:49,703: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('xxxxxx: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /api/people/10</p>

<p>xxxxxx should be replaced with -----> urllib3.connection.HTTPConnection object</p>

Hi there, my guess is that urllib3 isn't automatically picking up on our proxy settings. You'll have to configure them manually yourself (it's at http://proxy.server:3128), or, possibly simpler, just use the "requests" library which is easier to use and picks up the proxy config automatically..

You were correct; using the requests library is easier and works. Thanks

:)