dify icon indicating copy to clipboard operation
dify copied to clipboard

Failed to save file privkeys

Open kenxt opened this issue 11 months ago • 3 comments

Self Checks

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

Dify version

0.15.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Deploy Dify with local source code on two virtual hosts. One host (12.1.1.216) installs Redis, PostgreSQL, Weaviate, and Dify API/Worker Service, while the other host (12.1.1.218) installs Dify Web. After completing the installation according to the official documentation, started the services.

When accessing http://web-server-ip, a normal page is displayed. However, after entering the email, username, and password and confirming, an error is prompted: Setup failed: An error occurred (MissingContentLength) when calling the PutObject operation: Unknown

The API server prompts the following error message:

ERROR [account_service.py:846] e0d02baded Setup account failed, email: mailname@mailserver, name: kenxt
Traceback (most recent call last):
File "/opt/dify/api/services/account_service.py", line 834, in setup
TenantService.create_owner_tenant_if_not_exist(account=account, is_setup=True)
File "/opt/dify/api/services/account_service.py", line 591, in create_owner_tenant_if_not_exist
tenant = TenantService.create_tenant(name=f"{account.name}'s Workspace", is_setup=is_setup)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/dify/api/services/account_service.py", line 568, in create_tenant
tenant.encrypt_public_key = generate_key_pair(tenant.id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/dify/api/libs/rsa.py", line 21, in generate_key_pair
storage.save(filepath, pem_private)
File "/opt/dify/api/extensions/ext_storage.py", line 80, in save
raise e
File "/opt/dify/api/extensions/ext_storage.py", line 77, in save
self.storage_runner.save(filename, data)
File "/opt/dify/api/extensions/storage/aws_s3_storage.py", line 52, in save
self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data)
File "/opt/dify/api/.venv/lib/python3.12/site-packages/botocore/client.py", line 569, in _api_call
return self._make_api_call(operation_name, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/dify/api/.venv/lib/python3.12/site-packages/botocore/client.py", line 1023, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MissingContentLength) when calling the PutObject operation: Unknown

How to deal with this problem?

✔️ Expected Behavior

logined in , work well

❌ Actual Behavior

browser network tab : An HTTP 400 error is displayed: Request URL: http://12.1.1.216:5001/console/api/setup Request Method: POST Status Code: 400 BAD REQUEST Remote Address: 12.1.1.216:5001 Referrer Policy: strict-origin-when-cross-origin

Image

kenxt avatar Feb 19 '25 09:02 kenxt

Hey @kenxt! 👋 I'm here to help you with any bugs, questions, or contributions you have for Dify. Let's squash those bugs together!

The error you're encountering, "MissingContentLength," typically occurs when the AWS S3 client requires a content length for the data being uploaded, but it is not provided. This can happen if the data is a stream or a generator that does not have a predefined content length.

To address this issue, you can try the following solutions:

  1. Ensure Data Has a Content Length: If the data being uploaded is a stream, make sure it has a defined content length. You can calculate the length of the data before passing it to the put_object method.

  2. Modify the save Method: Update the save method in aws_s3_storage.py to include the ContentLength parameter when calling put_object. Here's an example of how you might modify the method:

    def save(self, filename, data):
        content_length = len(data)  # Calculate the content length
        self.client.put_object(Bucket=self.bucket_name, Key=filename, Body=data, ContentLength=content_length)
    

    This modification explicitly sets the content length, which should resolve the "MissingContentLength" error [1].

  3. Check for Streamed Data: If the data is being streamed, ensure that the stream provides a way to determine its length, or consider buffering the data to calculate its length before uploading.

By implementing these changes, you should be able to resolve the error and proceed with the setup process successfully.

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[bot] avatar Feb 19 '25 09:02 dosubot[bot]

Can you check the oss settings?

botocore.exceptions.ClientError: An error occurred (MissingContentLength) when calling the PutObject operation: Unknown

There is some thing wrong with this config.

crazywoola avatar Feb 19 '25 09:02 crazywoola

I modified the code in aws_s3_storage.py, checked the oss settings, but there are still errors.

kenxt avatar Feb 19 '25 10:02 kenxt