Recent SSL Error - urllib3.exceptions.MaxRetryError

Hi. 

I have 2 APIs on GCP, they're dockerized. I got communications between those 2 APIs. Lately one of them is throwing me an SSL error. 

Havent update anything, nor change any code. 

First error:

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.9/site-packages/uvicorn/workers.py", line 66, in init_process
    super(UvicornWorker, self).init_process()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Main.py", line 2, in <module>
    from Routes.ShippingRoute import shippingRouter
  File "/Routes/ShippingRoute.py", line 10, in <module>
    from Storage.GBucket import uploadToBucket
  File "/Storage/GBucket.py", line 13, in <module>
    bucket = gcsStorageClient.get_bucket(BUCKET_NAME)
  File "/usr/local/lib/python3.9/site-packages/google/cloud/storage/client.py", line 767, in get_bucket
    bucket.reload(
  File "/usr/local/lib/python3.9/site-packages/google/cloud/storage/bucket.py", line 1086, in reload
    super(Bucket, self).reload(
  File "/usr/local/lib/python3.9/site-packages/google/cloud/storage/_helpers.py", line 246, in reload
    api_response = client._get_resource(
  File "/usr/local/lib/python3.9/site-packages/google/cloud/storage/client.py", line 372, in _get_resource
    return self._connection.api_request(
  File "/usr/local/lib/python3.9/site-packages/google/cloud/storage/_http.py", line 72, in api_request
    return call()
  File "/usr/local/lib/python3.9/site-packages/google/api_core/retry.py", line 349, in retry_wrapped_func
    return retry_target(
  File "/usr/local/lib/python3.9/site-packages/google/api_core/retry.py", line 207, in retry_target
    raise exceptions.RetryError(
google.api_core.exceptions.RetryError: Deadline of 120.0s exceeded while calling target function, last exception: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1129)')))"
```

Second Error: 

```
"Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='myApiUrl', port=443): Max retries exceeded with url: /updateOrders (Caused by SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1129)')))"
```

Requirements File:

```
-i https://pypi.org/simple
anyio==3.6.2
cachetools==5.2.1
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.0.1
click==8.1.3
colorama==0.4.6
cryptography==40.0.1
fastapi==0.89.1
fuzzywuzzy==0.18.0
google-api-core==2.11.0
google-auth==2.16.0
google-cloud-core==2.3.2
google-cloud-storage==2.7.0
google-crc32c==1.5.0
google-resumable-media==2.4.0
googleapis-common-protos==1.58.0
greenlet==2.0.1
gunicorn==20.1.0
h11==0.14.0
idna==3.4
levenshtein==0.20.9
ndg-httpsclient==0.5.1
numpy==1.24.2
pandas==1.5.3
protobuf==4.21.12
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pydantic==1.10.4
pymysql==1.0.2
pyopenssl==23.1.1
pypdf==3.2.1
python-dateutil==2.8.2
python-dotenv==0.21.0
python-levenshtein==0.20.9
python-multipart==0.0.5
pytz==2022.7.1
rapidfuzz==2.13.7
requests==2.31.0
rsa==4.9
setuptools==68.0.0 ; python_version >= '3.7'
six==1.16.0
sniffio==1.3.0
sqlalchemy==1.4.46
starlette==0.22.0
suds==1.1.2
typing-extensions==4.4.0
unidecode==1.3.6
urllib3==2.0.3
uvicorn==0.20.0
```

It started happening like 2 weeks ago. Already downgraded pyton version, requests version, pyopenssl version, nothing seems to work.



Both errors have the following:

```
(Caused by SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1129)')))"
```

In other words, there's a protocol error way far down in TLS way below the level of requests or urllib3. The `SSLZeroReturnError` happens when a `recv` call in the C-level code in the ssl library does not receive any data in violation of the protocol.

This indicates to me that some intermediary (likely run by GCP since you're having errors talking to Google's services as well as your own) is causing you problems. I'd file a support ticket with GCP.

Hey. 

I dont really think this is a Google Issue. I've create a new separated account and uploaded the same image to the Container Registry and ran in on GCR. Still the same error trying to communicate with my other api.

```
ssl.SSLEOFError: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)
```
```
requests.exceptions.SSLError: HTTPSConnectionPool(host='https://myapiurl.com/updateOrders', port=443): Max retries exceeded with url: /updateOrders (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1002)')))
```

My code is as simple as this.


```python
def MicroservicesSincronization(correct_guides: list[CorrectGuides], Company):
  
      orders = [DbGuides(OrderNumber = x.OrderNumber, GuideNumber = x.GuideNumber, Company = Company) for x in 
                                      correct_guides]
  
      response = ECommerceCommunicationsAPI.UpdateOrders(orders)
      
      print(f"[E-CommerceCommunications] sent orders: {response.status_code}")

```

And the actual UpdateOrders

```python
@staticmethod
    def UpdateOrders(Orders: list[DbGuides]):

        payload = []

        for order in Orders:

            tracking_urls = {
            "Domina" : f"https://oriontracking.infokairos.com.co/envios/{order.GuideNumber}/tracking/cliente",
            "E-Box" : f"https://enviexpresslogistica.com/tracking/result/?NoGuia={order.GuideNumber}",
            "Coordinadora" : f"https://www.coordinadora.com/portafolio-de-servicios/servicios-en-linea/rastrear-guias/?guia={order.GuideNumber}"
            }

            orderJson = {
                "OrderNumber" : order.OrderNumber,
                "GuideNumber" : order.GuideNumber,
                "Company" :  order.Company,
                "Tracking_URL" : tracking_urls[order.Company]
            }

            payload.append(orderJson)
            
        with requests.Session() as Ses:
            response = Ses.post("https://myapiurl.com/updateOrders", json = payload)

            return response

```

I have tried doing a normal request (without the context manager) but its essentialy the same. 

Updated my requirements file.

```requirements.txt
-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
```

Used Docker Image: 
```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
```

Appreciate any help.






Hi there! Thanks for opening this issue. Unfortunately, it seems this is a request for help instead of a report of a defect in the project. Please use [StackOverflow](https://stackoverflow.com) for general usage questions instead and only report defects here.

Same Error. Use this version fix the error. but I don't know why.

```
requests==2.31.0
ws4py
urllib3==1.26.12
```