Solution skill
fix: MissingContentLength in boto3 version 1.36.1
Complete solution
Shows how to fix fix: MissingContentLength in boto3 version 1.36.1. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
For "An error occurred (MissingContentLength) when calling the PutObject operation: Unknown": install boto3 version 1.36.1 and django-storages. boto3 1.36.0 enabled checksum calculation and validation by default, which many S3-compatible providers (DigitalOcean Spaces, OCI, Linode, Contabo, iDrive, Hitachi) do not support yet, producing MissingContentLength on PutObject.
An error occurred (MissingContentLength) when calling the PutObject operation: UnknownSteps
- boto3 1.36.0 enabled checksum calculation and validation by default, which many S3-compatible providers (DigitalOcean Spaces, OCI, Linode, Contabo, iDrive, Hitachi) do not support yet, producing
MissingContentLengthon PutObject. Fix it by opting out of the new defaults. Either set the environment variables: - AWSREQUESTCHECKSUMCALCULATION=WHENREQUIRED
AWSRESPONSECHECKSUMVALIDATION=WHENREQUIRED
- or pass a botocore Config:
- from botocore.config import Config
config = Config(requestchecksumcalculation='WHENREQUIRED', responsechecksumvalidation='WHENREQUIRED') s3 = boto3.resource('s3', config=config, endpointurl='YOURENDPOINT', awsaccesskeyid='YOURKEY', awssecretaccess_key [your value]
- Use boto3 1.36.5 or newer, since an s3transfer bug that stopped these options applying to high-level S3 operations was fixed there. Downgrading to 1.35.99 also works but is the weaker option.
- Install
boto3version1.36.1anddjango-storages. - Configure Django to use S3 for file storage.
- Attempt to upload a file to S3.
When to use
You are seeing this: https://github.com/boto/boto3/issues/4398: Issue boto/boto3#4398 (closed, 22 comments): ### Describe the bug --- Use this skill when you run into "fix: MissingContentLength in boto3 version 1.36.1".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: boto3 1.36.0, boto3 1.36.5, 1.35.99, 1.36.1, django-storages 1.14.4. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Sources
- https://github.com/boto/boto3/issues/4398:
Evidence
Issue gh:boto/boto3#4398: the reporter asked: Issue boto/boto3#4398 (closed, 22 comments): ### 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: UnknownSteps to Reproduce
- Install
boto3version1.36.1anddjango-storages. - Configure Django to use S3 for file storage.
- Attempt to upload a file to S3.
Environment
boto3version:1.36.1django-storagesversion: django-storages==1.14.4- Django version:... The verified answer was: boto3 1.36.0 enabled checksum calculation and validation by default, which many S3-compatible providers (DigitalOcean Spaces, OCI, Linode, Contabo, iDrive, Hitachi) do not support yet, producing
MissingContentLengthon PutObject. Fix it by opting out of the new defaults. Either set the environment variables:
AWSREQUESTCHECKSUMCALCULATION=WHENREQUIRED AWSRESPONSECHECKSUMVALIDATION=WHENREQUIRED
or pass a botocore Config:
from botocore.config import Config config = Config(requestchecksumcalculation='WHENREQUIRED', responsechecksumvalidation='WHENREQUIRED') s3 = boto3.resource('s3', config=config, endpointurl='YOURENDPOINT', awsaccesskeyid='YOURKEY', awssecretaccess_key [your value]
Use boto3 1.36.5 or newer, since an s3transfer bug that stopped these options applying to high-level S3 operations was fixed there. Downgrading to 1.35.99 also works but is the weaker option. Evidence thread: https://github.com/boto/boto3/issues/4398
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_f01SI5xkYwkRzF7Wj57sfA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">fix: MissingContentLength in boto3 version 1.36.1 <span>— Vectle</span></a>