FastAPI - GCP - Docker。SSLEOF 错误。UNEXPECTED_EOF_WHILE_READING

Dan*_*n V 5 python ssl google-cloud-platform fastapi

因此,我在 GCP 上安装了一个微服务基础设施,它是用 Python、FastAPI 制作的,并且是 Docker 化的。我通过 HTTP 请求在这些 API(大约 7 个 API)之间进行通信。三周前,在我没有触及任何代码的情况下,一个错误开始出现。

这是Shipping API -> E-CommerceCommunication API 之间的通信。

这是开始发生的错误。

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='anyurl', port=443): Max retries exceeded with url: /anyEndpoint (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)')))
Run Code Online (Sandbox Code Playgroud)

奇怪的是,这种情况发生在 Shipping API 上,在它生成指南(这是一个 HTTP 请求)之后

因此,工作流程如下:生成指南(HTTP 请求)-> 为指南生成 PDF(HTTP 请求)-> 将运输信息发送到电子商务(HTTP 请求。这是失败的地方)。

这是我的 dockerfile

FROM python:3.11-slim-bookworm

COPY . . 

ENV PYTHONUNBUFFERED=1

RUN pip install -r requirements.txt

CMD exec gunicorn --bind :$PORT --workers 4 --worker-class uvicorn.workers.UvicornWorker --timeout 3600 Main:app
Run Code Online (Sandbox Code Playgroud)

这是我的要求文件。

-i https://pypi.org/simple
anyio==3.7.0 ; python_version >= '3.7'
cachetools==5.3.1 ; python_version >= '3.7'
certifi==2023.5.7 ; python_version >= '3.6'
charset-normalizer==3.1.0 ; python_full_version >= '3.7.0'
click==8.1.3 ; python_version >= '3.7'
colorama==0.4.6 ; platform_system == 'Windows'
fastapi==0.99.1
fuzzywuzzy==0.18.0
google-api-core==2.11.1 ; python_version >= '3.7'
google-auth==2.21.0 ; python_version >= '3.6'
google-cloud-core==2.3.2 ; python_version >= '3.7'
google-cloud-storage==2.10.0
google-crc32c==1.5.0 ; python_version >= '3.7'
google-resumable-media==2.5.0 ; python_version >= '3.7'
googleapis-common-protos==1.59.1 ; python_version >= '3.7'
greenlet==2.0.2 ; platform_machine == 'aarch64' or (platform_machine == 'ppc64le' or (platform_machine == 'x86_64' or (platform_machine == 'amd64' or (platform_machine == 'AMD64' or (platform_machine == 'win32' or platform_machine == 'WIN32')))))
gunicorn==20.1.0
h11==0.14.0 ; python_version >= '3.7'
idna==3.4 ; python_version >= '3.5'
levenshtein==0.21.1
numpy==1.25.0 ; python_version >= '3.10'
pandas==2.0.3
protobuf==4.23.3 ; python_version >= '3.7'
pyasn1==0.5.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
pyasn1-modules==0.3.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
pydantic==1.10.10 ; python_version >= '3.7'
pymysql==1.1.0
pypdf==3.12.0
python-dateutil==2.8.2 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
python-dotenv==1.0.0
python-multipart==0.0.6
pytz==2023.3
rapidfuzz==3.1.1 ; python_version >= '3.7'
requests==2.31.0 ; python_version >= '3.7'
rsa==4.9 ; python_version >= '3.6' and python_version < '4'
setuptools==68.0.0 ; python_version >= '3.7'
six==1.16.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
sniffio==1.3.0 ; python_version >= '3.7'
sqlalchemy==2.0.17
starlette==0.27.0 ; python_version >= '3.7'
suds==1.1.2
typing-extensions==4.7.1 ; python_version >= '3.7'
tzdata==2023.3 ; python_version >= '2'
urllib3==1.26.16 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
uvicorn==0.22.0
Run Code Online (Sandbox Code Playgroud)

这是来自 Shipping API -> E-CommerceComm-API 的请求

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='anyurl', port=443): Max retries exceeded with url: /anyEndpoint (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)')))
Run Code Online (Sandbox Code Playgroud)

我将 docker python 映像设置为 Python:3,但将其更改为实际的映像。删除了所有要求并重新安装卸载了 pyopenssl 尝试将容器推送到新的 Google 实例。

上面没有任何效果。

sok*_*efe 1

我受到了同样的错误的影响,设置几乎相同,并且从requests到 的切换httpx对我有用。我仍然不能 100% 确定为什么会这样,但更改requests.posthttpx.post可能会解决该错误。