How to Fix Azure Blob Storage ConnectionResetError 10054 in Python (On-Prem Windows VM Guide)

You tested your connection. You checked your code. You even uploaded the file manually through the Azure portal and it worked perfectly. But the moment you run your Python script on your on-premises Windows VM, you get this:

ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

How to Fix Azure Blob Storage ConnectionResetError 10054 in Python (On-Prem Windows VM Guide)

This guide explains exactly why this happens and walks you through every fix, proxy settings, firewall rules, SDK
configuration, and more; so, your upload works the same way your manual upload does.

What Causes Azure Blob Storage Upload Error 10054 in Python?

This error usually comes from the network, not your code.

Common causes:

  • Firewall blocking requests
  • Proxy not configured
  • Azure IP not whitelisted
  • SSL inspection interrupting uploads
  • Large/chunked uploads failing

Quick Troubleshooting Checklist

Start with this quick check to identify the issue fast:

  • VM public IP added in Azure Storage firewall
  • Proxy configured in Python
  • max_concurrency = 1 set
  • SDK version is 12.x or higher
  • Antivirus/SSL inspection tested
  • Blob URL opens in browser
  • Tried uploading a small file

If any of the above is missing, follow the steps below to fix it.

Prerequisites

Make sure you have:

  • Python 3.7 or higher
  • Azure SDK installed
pip install "azure-storage-blob>=12.0.0"
  • Azure Storage Account and container
  • Outbound internet access from VM
  • Storage Account name and key

Authentication Methods (Important)

Choose the correct method based on your setup.

1. Connection String (Access Key)

Best for quick setups and testing.

connection_string = "DefaultEndpointsProtocol=https;AccountName=...;AccountKey=..."
blob_service_client = BlobServiceClient.from_connection_string(connection_string)

2. SAS Token

Best when you want limited access.

sas_url = "https://<account>.blob.core.windows.net/<container>/<blob>?<sas_token>"

3. DefaultAzureCredential (Production)

Best for secure enterprise setups.

from azure.identity import DefaultAzureCredential

credential = DefaultAzureCredential()
blob_service_client = BlobServiceClient(
    account_url="https://<account>.blob.core.windows.net",
    credential=credential
)

Tip: If manual upload works with access key, start with connection string.

Step 1: Check Azure Storage Firewall

Go to: Azure Portal → Storage Account → Networking

  • Enable access for your VM’s public IP
  • Or allow all networks (for testing)

Tip: Search “what is my IP” from your VM

Step 2: Configure Proxy (Critical for On-Prem)

If your environment uses a proxy:

import os

os.environ["HTTPS_PROXY"] = "http://proxy-ip:port"
os.environ["HTTP_PROXY"] = "http://proxy-ip:port"

Step 3: Fix Upload Settings (Most Important)

Use stable upload settings:

max_concurrency = 1
max_block_size = 4 * 1024 * 1024

Why this works:

  • Prevents multiple connections
  • Avoids firewall triggers
  • Improves stability

Step 4: Test with Small File First

Start small:

  • Upload .txt file
  • Then small PDF
  • Then large file

If small works but large fails → network limitation.

Step 5: Check Antivirus / SSL Inspection

Corporate systems often inspect HTTPS traffic.

This can:

  • Reset connections
  • Break uploads

Test by:

  • Temporarily disabling antivirus
  • Whitelisting Azure endpoints

Step 6: Verify Connectivity

Open in browser:

https://<your-storage>.blob.core.windows.net/
  • If it fails → network issue
  • If it works → Python config issue

Error Diagnosis Table

SymptomCauseSolution
Works on Mac, fails on VMFirewall/ProxyStep 1, 2
Fails on large filesChunk uploadStep 3
Fails instantlyIP blockedStep 1
Random failuresSSL inspectionStep 5
Auth errorWrong keyAuth section

Complete Working Script: Copy and Use

import os
from azure.storage.blob import BlobServiceClient

# Optional proxy
# os.environ["HTTPS_PROXY"] = "http://proxy-ip:port"

CONNECTION_STRING = "your_connection_string"
CONTAINER_NAME = "your-container"
FILE_PATH = "test.pdf"
BLOB_NAME = "test.pdf"

def upload_blob():
    try:
        blob_service_client = BlobServiceClient.from_connection_string(
            CONNECTION_STRING,
            max_single_put_size=4 * 1024 * 1024,
            max_block_size=4 * 1024 * 1024
        )

        blob_client = blob_service_client.get_blob_client(
            container=CONTAINER_NAME,
            blob=BLOB_NAME
        )

        with open(FILE_PATH, "rb") as data:
            blob_client.upload_blob(
                data,
                overwrite=True,
                max_concurrency=1,
                timeout=300
            )

        print("Upload successful")

    except Exception as e:
        print(f"Upload failed: {e}")

upload_blob()

This error is not a coding issue in most cases. It typically comes from network-related factors such as restricted outbound connectivity, missing or incorrect proxy configuration, Azure Storage firewall rules blocking your VM’s IP, or show the upload process handles chunking and concurrency.

Once you address these underlying issues, your Python script will upload files to Azure Blob Storage consistently without connection resets.

FAQs

What is Azure Blob Storage upload error 10054 in Python?

Azure Blob Storage upload error 10054 occurs when the connection between your Python script and Azure is forcibly closed, usually due to network restrictions, proxy issues, or firewall rules blocking the request.

Why does Azure Blob upload work manually but fail in Python?

Manual uploads through the Azure portal use browser-based networking, which may bypass proxy or firewall restrictions. Python scripts require proper proxy configuration and network access, which often causes failures on on-prem VMs.

How do I fix ConnectionResetError 10054 in Azure Blob Storage?

To fix this error, whitelist your VM’s public IP in Azure Storage, configure proxy settings in Python, reduce upload concurrency to 1, and ensure your network allows outbound HTTPS traffic.

How do I find my VM public IP for Azure firewall?

Open a browser on your VM and search “what is my IP.” Use that public IP address in Azure Storage firewall settings to allow access.

Which Python SDK version should I use for Azure Blob Storage?

Use azure-storage-blob version 12.x or higher, as older versions may not support modern authentication and stable upload handling.

Can proxy settings cause Azure Blob upload errors?

Yes, proxy misconfiguration is one of the most common causes. If your environment uses a proxy, you must set HTTP_PROXY and HTTPS_PROXY variables in your Python script.

Does file size affect Azure Blob upload error 10054?

Yes, large files trigger chunked uploads and multiple connections, which can fail in restricted networks. Use smaller block sizes and set max_concurrency to 1.

How do I test Azure Blob connectivity from a VM?

You can test connectivity by opening https://your-storage-account.blob.core.windows.net/ in a browser or using curl from command prompt to confirm network access.

Does antivirus or SSL inspection cause this error?

Yes, antivirus or SSL inspection tools can interrupt HTTPS uploads and reset connections, especially in corporate environments.

Can I use Managed Identity instead of access key?

Yes, you can use DefaultAzureCredential for secure authentication in production environments, especially in Azure-hosted services.

Why does the same code work on another machine?

The other machine likely has fewer network restrictions, proper proxy configuration, or direct internet access, unlike your on-prem VM.

What is the fastest way to fix Azure Blob upload issues in Python?

Start by checking firewall rules, setting proxy correctly, reducing concurrency, and testing with a small file. These steps resolve most cases quickly.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply