前言
尝试用Python做一个图片自动处理工具,方便淘宝卖家制作首页图。结果在安装OpenCV的时候就遇到了这种尴尬问题。
问题
根据错误提示可知是访问超时。
或者以下错误时
Traceback (most recent call last):
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\urllib3\connection.py", line 364, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\urllib3\connection.py", line 501, in _connect_tls_proxy
socket = ssl_wrap_socket(
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\urllib3\util\ssl_.py", line 453, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\urllib3\util\ssl_.py", line 495, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "C:\Users\SlowFeather\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\SlowFeather\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create
self.do_handshake()
File "C:\Users\SlowFeather\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "D:\PROJECT\ProcessingImg\venv\lib\site-packages\urllib3\util\retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.tinify.com', port=443): Max retries exceeded with url: /shrink (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)')))
解决
更改Pip下载源即可
国内源
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
临时解决方案
pip install -i 网址 所需要安装的库名
列如
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
Linux解决方案
Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹),内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
Windows解决方案
windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip
,新建文件pip.ini
,内容如下:
[global]
trusted-host = pypi.tuna.tsinghua.edu.cn
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Mac解决方案
Mac下,在用户家目录~/.pip/pip.conf文件,内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple