Skip to main content
 首页 » 编程设计

python之Pip 错误,OSError Errno 22 参数无效

2024年10月01日8wuhuacong

使用pip搜索或安装包时,出现如下错误:

pip3 search validate 
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(22, 'Invalid argument'))': /pypi 
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(22, 'Invalid argument'))': /pypi 
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(22, 'Invalid argument'))': /pypi 
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(22, 'Invalid argument'))': /pypi 
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(22, 'Invalid argument'))': /pypi 
Exception: 
Traceback (most recent call last): 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 595, in urlopen 
    chunked=chunked) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 352, in _make_request 
    self._validate_conn(conn) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 831, in _validate_conn 
    conn.connect() 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connection.py", line 289, in connect 
    ssl_version=resolved_ssl_version) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py", line 308, in ssl_wrap_socket 
    return context.wrap_socket(sock, server_hostname=server_hostname) 
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket 
    _context=self, _session=session) 
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 791, in __init__ 
    self.getpeername() 
OSError: [Errno 22] Invalid argument 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/adapters.py", line 423, in send 
    timeout=timeout 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 668, in urlopen 
    release_conn=release_conn, **response_kw) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 668, in urlopen 
    release_conn=release_conn, **response_kw) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 668, in urlopen 
    release_conn=release_conn, **response_kw) 
  [Previous line repeated 1 more times] 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 640, in urlopen 
    _stacktrace=sys.exc_info()[2]) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/util/retry.py", line 287, in increment 
    raise MaxRetryError(_pool, url, error or ResponseError(cause)) 
pip._vendor.requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /pypi (Caused by ProtocolError('Connection aborted.', OSError(22, 'Invalid argument'))) 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "/usr/local/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main 
    status = self.run(options, args) 
  File "/usr/local/lib/python3.6/site-packages/pip/commands/search.py", line 45, in run 
    pypi_hits = self.search(query, options) 
  File "/usr/local/lib/python3.6/site-packages/pip/commands/search.py", line 62, in search 
    hits = pypi.search({'name': query, 'summary': query}, 'or') 
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xmlrpc/client.py", line 1112, in __call__ 
    return self.__send(self.__name, args) 
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xmlrpc/client.py", line 1452, in __request 
    verbose=self.__verbose 
  File "/usr/local/lib/python3.6/site-packages/pip/download.py", line 775, in request 
    headers=headers, stream=True) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 522, in post 
    return self.request('POST', url, data=data, json=json, **kwargs) 
  File "/usr/local/lib/python3.6/site-packages/pip/download.py", line 386, in request 
    return super(PipSession, self).request(method, url, *args, **kwargs) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 475, in request 
    resp = self.send(prep, **send_kwargs) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 596, in send 
    r = adapter.send(request, **kwargs) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/cachecontrol/adapter.py", line 47, in send 
    resp = super(CacheControlAdapter, self).send(request, **kw) 
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/adapters.py", line 487, in send 
    raise ConnectionError(e, request=request) 
pip._vendor.requests.exceptions.ConnectionError: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /pypi (Caused by ProtocolError('Connection aborted.', OSError(22, 'Invalid argument'))) 

pip 版本:来自/usr/local/lib/python3.6/site-packages (python 3.6) 的 pip 9.0.1
Python版本:3.6.3
操作系统:macOS High Sierra 10.13

我试过重新安装 python 和 pip。我不相信我在使用任何代理,它可能不是防火墙(我可以 ping/dig pypi.python.org)。

经过一些额外的挖掘,运行 curl pypi.python.org 发出相同的错误:curl: (55) getpeername() failed with errno 22: Invalid argument。

请您参考如下方法:

就我而言,这是 macOS High Sierra 上 IPv6 的问题。要解决此问题,请打开您的网络首选项,从列表中选择 Wi-Fi,然后单击“高级...”。单击 TCP/IP 选项卡,然后将配置 IPv6 更改为仅本地链接。