Python请求中有许多“ConnectionRefusedError:[WinError 10061]”

2024-04-28 21:08:21 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我知道下面有很多代码要看,但我完全被难住了,因为我在使用python时从来没有遇到过这样的问题。在

我希望使用“请求”模块来帮助我加快一些基于web的工作活动。我根据开发人员的要求下载了zipball并运行了“设置.py将其安装到“site packages”目录中。在

我已经验证了所有的内容确实在它应该的位置,理论上我应该能够导入它然后使用它,但是当我输入任何代码来提出一个新的请求时,比如:
r=请求.get('https://api.github.com/events') 下面是大量的错误,我一个字也听不懂。在

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

Tags: inpylibpackageslocallinesiteconnection
2条回答

我回答了我自己的问题,因为我在URLLIB3的文档和python3.5的请求中做了更多的挖掘,发现根本问题是WIN错误10061。在

URLLIB3和请求从Internet Explorer的默认代理设置派生其设置。

通过将我的internet explorer代理设置重置为空,它解决了我的所有问题。在

出于某种原因,尽管我从未在这台机器上使用过internet explorer,但除了下载firefox之外,我用过的其他应用程序肯定已经更改了IE中的设置。可能是windows防火墙。在

希望将来有人能看到这个问题,从我的错误中吸取教训。在

很明显你有连接问题。如果不知道更多,我想这是由于代理问题。如果是这样,这里有一个stackoverflow answer来设置一个带有requests模块的代理。在

如果不是,1)什么操作系统?,2)pip的环境变量设置?3) 公司网络还是家庭?在

相关问题 更多 >