boto3: fix: MissingContentLength in boto3 version 1.36.1

Describe the bug


Description

I encountered an issue while using boto3 version 1.36.1 in conjunction with django-storages. When attempting to upload files to AWS S3, I received the following error:

An error occurred (MissingContentLength) when calling the PutObject operation: Unknown

Steps to Reproduce

  1. Install boto3 version 1.36.1 and django-storages.
  2. Configure Django to use S3 for file storage.
  3. Attempt to upload a file to S3.

Environment

  • boto3 version: 1.36.1
  • django-storages version: django-storages==1.14.4
  • Django version: django==5.1.2
  • Python version: python==3.11

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The file should upload successfully without any errors.

Current Behavior

The upload fails with the MissingContentLength error.

Reproduction Steps

I found that downgrading boto3 to version 1.34.131 resolves the issue, and file uploads work as expected.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

boto3 version: 1.36.1

Environment details (OS name and version, etc.)

ubuntu22.04 boto3 version: 1.36.1 - django-storages version: django-storages==1.14.4 - Django version: django==5.1.2 - Python version: python==3.11

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 17
  • Comments: 22 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Downgrading to boto3==1.35.95 seem to be fixing the problem, at least as a temporary solution

I can confirm that we are also facing same issue.

Django 5.1.5
django-storages 1.14.4

After upgrading boto3 to 1.36.1 (or to 1.36.2) we started getting error:

An error occurred (MissingContentLength) when calling the PutObject operation: None

When downgraded boto3 to 1.35.99 error disappears.

We are using DigitalOcean Spaces S3 compatible buckets.

If it helps anyone, to fix this in Github Action environment you need to add two envs vars:

AWS_REQUEST_CHECKSUM_CALCULATION: WHEN_REQUIRED
AWS_RESPONSE_CHECKSUM_VALIDATION: WHEN_REQUIRED

For me it fixed the issue trying to upload to s3 “compatible” storage

If it helps anyone, to fix this in Github Action environment you need to add two envs vars: AWS_REQUEST_CHECKSUM_CALCULATION: WHEN_REQUIRED AWS_RESPONSE_CHECKSUM_VALIDATION: WHEN_REQUIRED For me it fixed the issue trying to upload to s3 “compatible” storage


        from botocore.config import Config
        config = Config(
            request_checksum_calculation = 'WHEN_REQUIRED',
            response_checksum_validation = 'WHEN_REQUIRED',
        )
        s3_resource = boto3.resource(
                's3',
                config=config,
                endpoint_url='endpoint',
                aws_access_key_id='accesskey',
                aws_secret_access_key='secretkey'
        )

This solved the issue for OCI buckets, thank you

As mentioned, for those using third-party storage services, you can disable the new checksum behavior by setting request_checksum_calculation and response_checksum_validation to when_required. Please note that a bug related to these configuration options not applying to high-level S3 operations was fixed in s3transfer-0.11.2. You should update to at least boto3-1.36.5 for this option to work as intended. If you continue to have problems, please feel free to open a new issue.

If it helps anyone, to fix this in Github Action environment you need to add two envs vars:

AWS_REQUEST_CHECKSUM_CALCULATION: WHEN_REQUIRED AWS_RESPONSE_CHECKSUM_VALIDATION: WHEN_REQUIRED

For me it fixed the issue trying to upload to s3 “compatible” storage


        from botocore.config import Config
        config = Config(
            request_checksum_calculation = 'WHEN_REQUIRED',
            response_checksum_validation = 'WHEN_REQUIRED',
        )
        s3_resource = boto3.resource(
                's3',
                config=config,
                endpoint_url='endpoint',
                aws_access_key_id='accesskey',
                aws_secret_access_key='secretkey'
        )

This is also an issue with pyiceberg/s3fs

Thank you @zaosoula - it works when using the amazon.aws Ansible module as well.

Used the following settings:

- name: Upload file to S3
  aws_s3:
    # <removed all other stuff>
    aws_config:
       request_checksum_calculation: when_required
       response_checksum_validation: when_required

Downgraded to boto3==1.35.95 , now contabo and idrive both work

Hi @alireza-fa, thanks for reaching out. This is related to the recent announcement of new default checksum behavior starting in v1.36.0. I suspect this is likely an issue with django-storages.

Disclaimer: The AWS SDKs and CLI are designed for usage with official AWS services. We may introduce and enable new features by default, such as these new default integrity protections prior to them being supported or handled by third-party service implementations. You can disable the new behavior with the WHEN_REQUIRED value for the request_checksum_calculation and response_checksum_validation configuration options covered in Data Integrity Protections for Amazon S3.

Are you able to reproduce this behavior using AWS S3, or with default integrity options set to when-required?