How to fix "EOF occurred in violation of protocol" with download_blob() in Python?

Matt Schwartz 25 Reputation points
2024-09-24T20:55:20.6533333+00:00

I have python code that is trying to read a file in blob storage. I get this error:

azure.core.exceptions.ServiceRequestError: EOF occurred in violation of protocol (_ssl.c:1007)

after running:

blob_client.download_blob()

What am I doing wrong?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,929 questions
Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,537 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,199 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pinaki Ghatak 5,600 Reputation points Microsoft Employee Volunteer Moderator
    2024-09-25T09:55:39.4966667+00:00

    Hello @Matt Schwartz

    The error message you are seeing is related to SSL protocol.

    It is possible that the SSL connection is being closed unexpectedly. This can happen due to a number of reasons, such as network issues or server-side issues. To fix this issue, you can try the following steps:

    1. Upgrade the Azure Storage Blob client library for Python to the latest version. You can do this by running the following command: pip install --upgrade azure-storage-blob
    2. Try setting the max_concurrency parameter to a lower value when calling the download_blob() method. This can help reduce the load on the server and prevent the SSL connection from being closed unexpectedly. For example: blob_client.download_blob(max_concurrency=1)
    3. If the issue persists, you can try disabling SSL verification by setting the verify parameter to False when creating the BlobServiceClient or BlobClient object. However, this is not recommended for security reasons. For example: from azure.storage.blob import BlobServiceClient blob_service_client = BlobServiceClient.from_connection_string(conn_str, verify=False)

    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.