我尝试通过 https 从网站获取数据并收到 SSL 证书错误,但是当我在我的 mac 上运行时 - 一切正常。
我也尝试使用 curl 并得到了同样的错误,
curl: (35) error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol
我在 Docker 容器中运行解析器我的 Dockerfile:
FROM python:3.7
WORKDIR /parser
COPY ./requirements.txt .
RUN python -m pip install --upgrade pip
RUN pip install -r requirements.txt
COPY . /parser
我收到以下错误:
Traceback (most recent call last): │
│ File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen │
│ chunked=chunked, │
│ File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 376, in _make_request │
│ self._validate_conn(conn) │
│ File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn │
│ conn.connect() │
│ File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 394, in connect │
│ ssl_context=context, │
│ File "/usr/local/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 370, in ssl_wrap_socket │
│ return context.wrap_socket(sock, server_hostname=server_hostname) │
│ File "/usr/local/lib/python3.7/ssl.py", line 423, in wrap_socket │
│ session=session │
│ File "/usr/local/lib/python3.7/ssl.py", line 870, in _create │
│ self.do_handshake() │
│ File "/usr/local/lib/python3.7/ssl.py", line 1139, in do_handshake │
│ self._sslobj.do_handshake() │
│ ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1076) │
│ During handling of the above exception, another exception occurred: │
│ Traceback (most recent call last): │
│ File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send │
│ timeout=timeout │
│ File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen │
│ method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] │
│ File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 436, in increment │
│ raise MaxRetryError(_pool, url, error or ResponseError(cause)) │
│ urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='life.pravda.com.ua', port=443): Max retries exceeded with url: /health/ (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1076)')) │
│ )
我在 Dockerfile 中使用以下命令解决了我的问题:
RUN apt-get update \
&& apt-get install openssl \
&& apt-get install ca-certificates
并且还需要在requirements.txt
中添加python包pyopenssl
我是一名优秀的程序员,十分优秀!