Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

So I know that is a lot of code to look at down below, but I'm absolutely stumped because I've never had such an issue when using python.

I was hopeful to use the requests module to help me speed up some of my web based activities for work. I downloaded the zipball per the requests of the developers and ran "setup.py" to install it into the "site-packages" directory.

I've verified that all the content is indeed where it should be, and theoretically I should be able to import it and then use it, but the moment I type any code to make a new request such as:
r = requests.get(' https://api.github.com/events ') I get the MASSIVE stream of errors below, which I dont understand a word of.

  Traceback (most recent call last):
    File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\connection.py", line 135, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
    File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\util\connection.py", line 90, in create_connection
    raise err
    File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\util\connection.py", line 80, in create_connection
    sock.connect(sa)
**ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it**
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\connectionpool.py", line 554, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\connectionpool.py", line 748, in _prepare_proxy
    conn.connect()
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\connection.py", line 215, in connect
    conn = self._new_conn()
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\connection.py", line 144, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x03908510>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\connectionpool.py", line 609, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\packages\urllib3\util\retry.py", line 271, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /events (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x03908510>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    r = requests.get('https://api.github.com/events')
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Dakota\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests-2.8.1-py3.5.egg\requests\adapters.py", line 431, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /events (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x03908510>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)))

Im answering my own question because I've done more digging in the documentation of URLLIB3 and Requests for Python 3.5 and found that the root issue was a WIN Error 10061.

URLLIB3 and Requests derive their settings from the default proxy settings of Internet Explorer.

By resetting my internet explorer proxy settings to empty, it resolved all my issues.

For some reason, even though I've never used internet explorer on this machine except to download firefox, some other app I've used must have changed the settings in IE. Probably windows firewall.

Hopefully anyone who comes up in the future will see this question and learn from my errors.

It's clear that you are having connection issues. Without knowing more, I would guess this is due to a proxy problem. If so here's a stackoverflow answer to setup a proxy with the requests module.

If not, 1) What OS?, 2)Environment variables setup for pip? 3)Corporate Network or Home?

Indeed, the problem is in the Internet settings. How to fix:

  • Click on the gear in the upper right corner
  • Select an item "Internet options"
  • Go to the tab "Connections"
  • Click on "LAN settings"
  • Uncheck the item "Use a proxy server for..."
  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.