Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

botocore.exceptions.ClientError: The Content-Length header is required #15225

Closed
5 tasks done
engchina opened this issue Mar 7, 2025 · 2 comments · Fixed by #15261 or #15474
Closed
5 tasks done

botocore.exceptions.ClientError: The Content-Length header is required #15225

engchina opened this issue Mar 7, 2025 · 2 comments · Fixed by #15261 or #15474
Labels
🐞 bug Something isn't working

Comments

@engchina
Copy link
Contributor

engchina commented Mar 7, 2025

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

v1.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

While using s3 compatible object storage, and upload a file, error will occur:

it's an issue of boto3 >= 1.36.1, even latest one 1.37.8.
it's okay of version boto3==1.35.99.
reference: boto/boto3#4398

✔️ Expected Behavior

no error

❌ Actual Behavior

error log:

ent_version=1.0.0 (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1010)'))).
2025-03-07 08:18:06.962 ERROR [Dummy-2] [ext_storage.py:79] - Failed to save file upload_files/5d097fc2-5b69-4ac1-919b-195e621466b2/fbb713de-4a71-4094-9925-54ecda784719.txt
Traceback (most recent call last):
  File "/app/api/extensions/ext_storage.py", line 77, in save
    self.storage_runner.save(filename, data)
  File "/app/api/extensions/storage/oracle_oci_storage.py", line 26, in save
    self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data)
  File "/app/api/.venv/lib/python3.12/site-packages/botocore/client.py", line 570, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/botocore/context.py", line 124, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/botocore/client.py", line 1031, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MissingContentLength) when calling the PutObject operation: The Content-Length header is required
2025-03-07 08:18:06.964 ERROR [Dummy-2] [app.py:875] - Exception on /console/api/files/upload [POST]
Traceback (most recent call last):
  File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper
    resp = resource(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
    resp = meth(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/console/wraps.py", line 147, in decorated
    return view(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/libs/login.py", line 94, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/console/wraps.py", line 27, in decorated
    return view(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 696, in wrapper
    resp = f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/console/wraps.py", line 86, in decorated
    return view(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/controllers/console/files.py", line 72, in post
    upload_file = FileService.upload_file(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/services/file_service.py", line 67, in upload_file
    storage.save(file_key, content)
  File "/app/api/extensions/ext_storage.py", line 80, in save
    raise e
  File "/app/api/extensions/ext_storage.py", line 77, in save
    self.storage_runner.save(filename, data)
  File "/app/api/extensions/storage/oracle_oci_storage.py", line 26, in save
    self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data)
  File "/app/api/.venv/lib/python3.12/site-packages/botocore/client.py", line 570, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/botocore/context.py", line 124, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/botocore/client.py", line 1031, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MissingContentLength) when calling the PutObject operation: The Content-Length header is required
Copy link

dosubot bot commented Mar 7, 2025

The error you're encountering is related to the boto3 library versions >= 1.36.1, where the Content-Length header is required but not automatically set during file uploads to S3-compatible storage. This issue does not occur with boto3 version 1.35.99.

To resolve this, you can try the following approaches:

  1. Downgrade boto3: Temporarily downgrade to boto3 version 1.35.99, where this issue does not occur.

  2. Manually Set Content-Length: Modify the code to manually set the Content-Length header when calling the put_object method. You can calculate the content length from the data being uploaded and include it in the request.

  3. Check for Updates: Keep an eye on updates from the boto3 library or related discussions, as a fix might be released in future versions.

These steps should help you work around the issue until a permanent fix is available in the boto3 library.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot dosubot bot added the 🐞 bug Something isn't working label Mar 7, 2025
@engchina
Copy link
Contributor Author

engchina commented Mar 7, 2025

Is it a good solution? I see boto/boto3#4398, many other projects have done a downgrade.

Downgrade boto3: Temporarily downgrade to boto3 version 1.35.99, where this issue does not occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
1 participant