cannot access the create-by-file address when accessing the KB API #12155

Closed
opened 2026-02-21 19:06:04 -05:00 by yindo · 4 comments
Owner

Originally created by @LordLiu on GitHub (Mar 26, 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

1.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

import requests

# 设置 API 的 URL 和相关参数
dataset_id = "***"  # 替换为你的 dataset_id
api_key = "***"  # 替换为你的 API 密钥
file_path = "D:/Resource/AILLM.pdf"  # 替换为你的文件路径

# 构造请求的 URL
url = f"https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-file"

# 设置请求头
headers = {
    "Authorization": f"Bearer {api_key}"
}

# 构造表单数据
data = {
    "indexing_technique": "high_quality",
    "process_rule": {
        "rules": {
            "pre_processing_rules": [
                {"id": "remove_extra_spaces", "enabled": True},
                {"id": "remove_urls_emails", "enabled": True}
            ],
            "segmentation": {
                "separator": "###",
                "max_tokens": 500
            }
        },
        "mode": "custom"
    }
}

# 打开文件并上传
with open(file_path, "rb") as file:
    files = {
        "data": (None, f"{data}", "text/plain"),
        "file": (file.name, file, "application/octet-stream")
    }
    response = requests.post(url, headers=headers, files=files)


# 打印响应结果
print("响应状态码:", response.status_code)
print("响应内容:", response.json())

✔️ Expected Behavior

send a new file to existing db

Actual Behavior

{
"code": "method_not_allowed",
"message": "The method is not allowed for the requested URL.",
"status": 405
}

Originally created by @LordLiu on GitHub (Mar 26, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.0.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ``` import requests # 设置 API 的 URL 和相关参数 dataset_id = "***" # 替换为你的 dataset_id api_key = "***" # 替换为你的 API 密钥 file_path = "D:/Resource/AILLM.pdf" # 替换为你的文件路径 # 构造请求的 URL url = f"https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-file" # 设置请求头 headers = { "Authorization": f"Bearer {api_key}" } # 构造表单数据 data = { "indexing_technique": "high_quality", "process_rule": { "rules": { "pre_processing_rules": [ {"id": "remove_extra_spaces", "enabled": True}, {"id": "remove_urls_emails", "enabled": True} ], "segmentation": { "separator": "###", "max_tokens": 500 } }, "mode": "custom" } } # 打开文件并上传 with open(file_path, "rb") as file: files = { "data": (None, f"{data}", "text/plain"), "file": (file.name, file, "application/octet-stream") } response = requests.post(url, headers=headers, files=files) # 打印响应结果 print("响应状态码:", response.status_code) print("响应内容:", response.json()) ``` ### ✔️ Expected Behavior send a new file to existing db ### ❌ Actual Behavior { "code": "method_not_allowed", "message": "The method is not allowed for the requested URL.", "status": 405 }
yindo added the 🤔 cant-reproduce label 2026-02-21 19:06:04 -05:00
yindo closed this issue 2026-02-21 19:06:04 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 26, 2025):

@LordLiu Hello there! I'm here to help with bug fixes, answer your questions, and assist you in becoming a contributor.

The "method_not_allowed" error indicates that the HTTP method used is not supported by the endpoint. For the 'create-by-file' endpoint, the correct method is POST, which you are already using. Here are a few things to check:

  1. URL Format: Ensure the URL is correctly formatted. It should be:

    https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file
    

    Note the underscore in create_by_file instead of a hyphen.

  2. API Key and Dataset ID: Double-check that the api_key and dataset_id are correctly set and valid.

  3. Server Configuration: Since you are using a self-hosted setup, ensure that your server is configured to accept POST requests at this endpoint.

If these are correct and the issue persists, it might be related to server configuration or the endpoint itself. You may need to check server logs for more details or verify the server setup [1].

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] commented on GitHub (Mar 26, 2025): <!-- Greeting --> @LordLiu Hello there! I'm here to help with bug fixes, answer your questions, and assist you in becoming a contributor. <!-- Answer --> The "method_not_allowed" error indicates that the HTTP method used is not supported by the endpoint. For the 'create-by-file' endpoint, the correct method is `POST`, which you are already using. Here are a few things to check: 1. **URL Format**: Ensure the URL is correctly formatted. It should be: ``` https://api.dify.ai/v1/datasets/{dataset_id}/document/create_by_file ``` Note the underscore in `create_by_file` instead of a hyphen. 2. **API Key and Dataset ID**: Double-check that the `api_key` and `dataset_id` are correctly set and valid. 3. **Server Configuration**: Since you are using a self-hosted setup, ensure that your server is configured to accept `POST` requests at this endpoint. If these are correct and the issue persists, it might be related to server configuration or the endpoint itself. You may need to check server logs for more details or verify the server setup <sup>[[1]](https://github.com/langgenius/dify/issues/13565)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/05726203-8937-4de6-8dfe-939d54e9d05d?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/05726203-8937-4de6-8dfe-939d54e9d05d?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/05726203-8937-4de6-8dfe-939d54e9d05d?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/05726203-8937-4de6-8dfe-939d54e9d05d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/05726203-8937-4de6-8dfe-939d54e9d05d?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/05726203-8937-4de6-8dfe-939d54e9d05d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/05726203-8937-4de6-8dfe-939d54e9d05d?feedback_type=other)</sup>
Author
Owner

@LordLiu commented on GitHub (Mar 26, 2025):

@dosu another error occured:
响应状态码: 401
响应内容: {'code': 'unauthorized', 'message': 'Access token is invalid', 'status': 401}

@LordLiu commented on GitHub (Mar 26, 2025): @dosu another error occured: 响应状态码: 401 响应内容: {'code': 'unauthorized', 'message': 'Access token is invalid', 'status': 401}
Author
Owner

@dosubot[bot] commented on GitHub (Mar 26, 2025):

To resolve the "unauthorized" error with status code 401 indicating that the access token is invalid, ensure the following:

  1. Authorization Header: Verify that the Authorization header is correctly formatted and starts with "Bearer". It should look like this: Authorization: Bearer your_access_token.

  2. Token Validity: Check that the access token is valid and has not expired. If the token is invalid, you will need to obtain a new valid token.

  3. Correct Token Format: Ensure that the token does not include curly braces. Use Authorization: Bearer app-HH8eER525URsqACQRFC73snO instead of Authorization: Bearer {app-HH8eER525URsqACQRFC73snO}.

  4. API Key Verification: Double-check that the API Key is correct. An incorrect API Key can lead to authorization failures.

If the issue persists, you may need to regenerate the access token using the appropriate method in your setup [1][2].

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] commented on GitHub (Mar 26, 2025): <!-- Answer --> To resolve the "unauthorized" error with status code 401 indicating that the access token is invalid, ensure the following: 1. **Authorization Header**: Verify that the `Authorization` header is correctly formatted and starts with "Bearer". It should look like this: `Authorization: Bearer your_access_token`. 2. **Token Validity**: Check that the access token is valid and has not expired. If the token is invalid, you will need to obtain a new valid token. 3. **Correct Token Format**: Ensure that the token does not include curly braces. Use `Authorization: Bearer app-HH8eER525URsqACQRFC73snO` instead of `Authorization: Bearer {app-HH8eER525URsqACQRFC73snO}`. 4. **API Key Verification**: Double-check that the API Key is correct. An incorrect API Key can lead to authorization failures. If the issue persists, you may need to regenerate the access token using the appropriate method in your setup <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/controllers/service_api/wraps.py)</sup><sup>[[2]](https://github.com/langgenius/dify/issues/15706)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/6a28fdb0-ea0c-4e47-a7e1-318ed1c1741c?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/6a28fdb0-ea0c-4e47-a7e1-318ed1c1741c?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/6a28fdb0-ea0c-4e47-a7e1-318ed1c1741c?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/6a28fdb0-ea0c-4e47-a7e1-318ed1c1741c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6a28fdb0-ea0c-4e47-a7e1-318ed1c1741c?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/6a28fdb0-ea0c-4e47-a7e1-318ed1c1741c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/6a28fdb0-ea0c-4e47-a7e1-318ed1c1741c?feedback_type=other)</sup>
Author
Owner

@crazywoola commented on GitHub (Mar 26, 2025):

This is only for bug report, if you would like to ask a question, please head to Discussions.

[FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)

@crazywoola commented on GitHub (Mar 26, 2025): This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12155