detect_file_encodings TypeError: tuple indices must be integers or slices, not str #21011

Closed
opened 2026-02-21 20:10:15 -05:00 by yindo · 1 comment
Owner

Originally created by @zhaobingshuang on GitHub (Dec 12, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.11.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Image Image Image

✔️ Expected Behavior

No error reported.

Actual Behavior

TypeError: tuple indices must be integers or slices, not str

log

2025-12-12 09:24:41,900 INFO [document_indexing_task.py:85]  Start process document: 322916ed-6383-4f21-a543-ab265d711ae8
2025-12-12 09:24:42,93 ERROR [indexing_runner.py:55]  consume document failed
Traceback (most recent call last):
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\markdown_extractor.py", line 100, in parse_tups
    content = Path(filepath).read_text(encoding=self._encoding)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\software\uv\python\cpython-3.12.12-windows-x86_64-none\Lib\pathlib.py", line 1028, in read_text
    return f.read()
           ^^^^^^^^
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb0 in position 16: illegal multibyte sequence

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\indexing_runner.py", line 90, in run
    text_docs = self._extract(index_processor, requeried_document, processing_rule.to_dict())
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\indexing_runner.py", line 387, in _extract
    text_docs = index_processor.extract(extract_setting, process_rule_mode=process_rule["mode"])
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\index_processor\processor\paragraph_index_processor.py", line 30, in extract
    text_docs = ExtractProcessor.extract(
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\extract_processor.py", line 165, in extract
    return extractor.extract()
           ^^^^^^^^^^^^^^^^^^^
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\markdown_extractor.py", line 36, in extract
    tups = self.parse_tups(self._file_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\markdown_extractor.py", line 103, in parse_tups
    detected_encodings = detect_file_encodings(filepath)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\helpers.py", line 48, in detect_file_encodings
    if all(encoding["encoding"] is None for encoding in encodings):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\helpers.py", line 48, in <genexpr>
    if all(encoding["encoding"] is None for encoding in encodings):
           ~~~~~~~~^^^^^^^^^^^^
TypeError: tuple indices must be integers or slices, not str
2025-12-12 09:24:42,103 INFO [document_indexing_task.py:102]  Processed dataset: 2a278380-fd83-4568-a00a-05bc1c3b1189 latency: 0.2943989000050351
Originally created by @zhaobingshuang on GitHub (Dec 12, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [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, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.11.1 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce <img width="1455" height="693" alt="Image" src="https://github.com/user-attachments/assets/17114b02-dcef-4d94-94f4-d2c009d16505" /> <img width="1794" height="1347" alt="Image" src="https://github.com/user-attachments/assets/afd27568-0801-4a43-8133-1edcda3e15a8" /> <img width="1516" height="690" alt="Image" src="https://github.com/user-attachments/assets/60ffc4e6-4215-44d7-83a5-19e71570012e" /> ### ✔️ Expected Behavior No error reported. ### ❌ Actual Behavior TypeError: tuple indices must be integers or slices, not str log ``` 2025-12-12 09:24:41,900 INFO [document_indexing_task.py:85] Start process document: 322916ed-6383-4f21-a543-ab265d711ae8 2025-12-12 09:24:42,93 ERROR [indexing_runner.py:55] consume document failed Traceback (most recent call last): File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\markdown_extractor.py", line 100, in parse_tups content = Path(filepath).read_text(encoding=self._encoding) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\software\uv\python\cpython-3.12.12-windows-x86_64-none\Lib\pathlib.py", line 1028, in read_text return f.read() ^^^^^^^^ UnicodeDecodeError: 'gbk' codec can't decode byte 0xb0 in position 16: illegal multibyte sequence During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\indexing_runner.py", line 90, in run text_docs = self._extract(index_processor, requeried_document, processing_rule.to_dict()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\indexing_runner.py", line 387, in _extract text_docs = index_processor.extract(extract_setting, process_rule_mode=process_rule["mode"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\index_processor\processor\paragraph_index_processor.py", line 30, in extract text_docs = ExtractProcessor.extract( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\extract_processor.py", line 165, in extract return extractor.extract() ^^^^^^^^^^^^^^^^^^^ File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\markdown_extractor.py", line 36, in extract tups = self.parse_tups(self._file_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\markdown_extractor.py", line 103, in parse_tups detected_encodings = detect_file_encodings(filepath) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\helpers.py", line 48, in detect_file_encodings if all(encoding["encoding"] is None for encoding in encodings): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\project\IT\dify\1.11.1\source_code_run\dify-1.11.1\api\core\rag\extractor\helpers.py", line 48, in <genexpr> if all(encoding["encoding"] is None for encoding in encodings): ~~~~~~~~^^^^^^^^^^^^ TypeError: tuple indices must be integers or slices, not str 2025-12-12 09:24:42,103 INFO [document_indexing_task.py:102] Processed dataset: 2a278380-fd83-4568-a00a-05bc1c3b1189 latency: 0.2943989000050351 ```
yindo added the 🐞 bug label 2026-02-21 20:10:15 -05:00
yindo closed this issue 2026-02-21 20:10:15 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 12, 2025):

The TypeError happens because the detect_file_encodings function was recently changed to return a list of NamedTuples (FileEncoding) with attributes like encoding, confidence, and language, instead of dictionaries. However, the code in helpers.py still tries to access these as if they were dictionaries (e.g., encoding["encoding"]), which causes the error "tuple indices must be integers or slices, not str".

To fix this, update any code that accesses encoding["encoding"] to use attribute access: encoding.encoding. For example, change:

if all(encoding["encoding"] is None for encoding in encodings):

to

if all(encoding.encoding is None for encoding in encodings):

and similarly for any other dictionary-style access on FileEncoding objects.

This change aligns with how the output is used elsewhere, such as in markdown_extractor.py, and will resolve the TypeError. The root cause and the recent change are documented in PR #29022.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 12, 2025): <!-- Answer --> The TypeError happens because the detect_file_encodings function was recently changed to return a list of NamedTuples (FileEncoding) with attributes like encoding, confidence, and language, instead of dictionaries. However, the code in helpers.py still tries to access these as if they were dictionaries (e.g., encoding["encoding"]), which causes the error ["tuple indices must be integers or slices, not str"](https://github.com/langgenius/dify/blob/a8613f02337d2569d2574079e66164fa9dffe383/api/core/rag/extractor/helpers.py#L9-L50). To fix this, update any code that accesses encoding["encoding"] to use attribute access: encoding.encoding. For example, change: ```python if all(encoding["encoding"] is None for encoding in encodings): ``` to ```python if all(encoding.encoding is None for encoding in encodings): ``` and similarly for any other dictionary-style access on FileEncoding objects. This change aligns with how the output is used elsewhere, such as in markdown_extractor.py, and will resolve the TypeError. The root cause and the recent change are documented in [PR #29022](https://github.com/langgenius/dify/pull/29022). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/c37ca73d-cbeb-4a03-af52-998ebc98f6cd?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/c37ca73d-cbeb-4a03-af52-998ebc98f6cd?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/c37ca73d-cbeb-4a03-af52-998ebc98f6cd?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/c37ca73d-cbeb-4a03-af52-998ebc98f6cd?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c37ca73d-cbeb-4a03-af52-998ebc98f6cd?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/c37ca73d-cbeb-4a03-af52-998ebc98f6cd?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c37ca73d-cbeb-4a03-af52-998ebc98f6cd?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20TypeError%20happens%20because%20the%20detect_file_encodings%20function%20was%20recently%20changed%20to%20return%20a%20list%20of%20NamedTuples%20%28FileEncoding%29%20with%20attributes%20like%20encoding%2C%20confidence%2C%20and%20language%2C%20instead%20of%20dictionaries.%20However%2C%20the%20code%20in%20helpers.py%20still%20tries%20to%20access%20these%20as%20if%20they%20were%20dictionaries%20%28e.g.%2C%20encoding%5B%22encoding%22%5D%29%2C%20which%20causes%20the%20error%20%5B%22tuple%20indices%20must%20be%20integers%20or%20slices%2C%20not%20str%22%5D%28https%3A//github.com/langgenius/dify/blob/a8613f02337d2569d2574079e66164fa9dffe383/api/core/rag/extractor/helpers.py%23L9-L50%29.%0A%0ATo%20fix%20this%2C%20update%20any%20code%20that%20accesses%20encoding%5B%22encoding%22%5D%20to%20use%20attribute%20access%3A%20encoding.encoding.%20For%20example%2C%20change%3A%0A%0A%60%60%60python%0Aif%20all%28encoding%5B%22encoding%22%5D%20is%20None%20for%20encoding%20in%20encodings%29%3A%0A%60%60%60%0Ato%0A%60%60%60python%0Aif%20all%28encoding.encoding%20is%20None%20for%20encoding%20in%20encodings%29%3A%0A%60%60%60%0A%0Aand%20similarly%20for%20any%20other%20dictionary-style%20access%20on%20FileEncoding%20objects.%0A%0AThis%20change%20aligns%20with%20how%20the%20output%20is%20used%20elsewhere%2C%20such%20as%20in%20markdown_extractor.py%2C%20and%20will%20resolve%20the%20TypeError.%20The%20root%20cause%20and%20the%20recent%20change%20are%20documented%20in%20%5BPR%20%2329022%5D%28https%3A//github.com/langgenius/dify/pull/29022%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/29588)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21011