Numerous “ConnectionRefusedError: [WinError 10061]” in Python requests

人走茶凉 提交于 2020-01-15 03:51:06

问题


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',)))

回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/33314169/numerous-connectionrefusederror-winerror-10061-in-python-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!