UnicodeDecodeError #21816

Closed
opened 2026-02-21 20:14:26 -05:00 by yindo · 2 comments
Owner

Originally created by @sunw80910 on GitHub (Jan 21, 2026).

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.4

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

在使用docker部署的时候,修改了.env的部分配置
执行./generate_docker_compose 的时候,发生了报错

✔️ Expected Behavior

Generated docker-compose.yaml

Actual Behavior

UnicodeDecodeError: 'gbk' codec can't decode byte 0x8c in position 8053: illegal multibyte sequence

Originally created by @sunw80910 on GitHub (Jan 21, 2026). ### 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.4 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 在使用docker部署的时候,修改了.env的部分配置 执行./generate_docker_compose 的时候,发生了报错 ### ✔️ Expected Behavior Generated docker-compose.yaml ### ❌ Actual Behavior UnicodeDecodeError: 'gbk' codec can't decode byte 0x8c in position 8053: illegal multibyte sequence
yindo added the 🐞 bug label 2026-02-21 20:14:26 -05:00
yindo closed this issue 2026-02-21 20:14:26 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 21, 2026):

Hi @sunw80910! I'm Dosu and I’m helping the dify team.

The UnicodeDecodeError ('gbk' codec) happens because the generate_docker_compose script reads files like .env.example and docker-compose-template.yaml without specifying an encoding, so Python defaults to your system locale (often 'gbk' on Chinese Windows systems). If these files contain UTF-8 characters, this causes the error.

To fix this:

  1. Make sure all your .env, .env.example, and docker-compose-template.yaml files are saved as UTF-8 (without BOM).
  2. Run the script in an environment where the locale is set to UTF-8. For Docker, set LANG and LC_ALL to C.UTF-8 (or en_US.UTF-8 if C.UTF-8 isn't available), and PYTHONIOENCODING=utf-8 in your Dockerfile or Compose file. This is now the recommended setting and is used in recent Dify versions (PR #30621).
  3. As a local workaround, you can edit the generate_docker_compose script and add encoding="utf-8" to all open() calls.

This issue is discussed in existing issues and docs, and the root cause is the missing encoding argument in the script (see code). Proper locale and encoding settings in Docker are critical to avoid these errors.

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 (Jan 21, 2026): <!-- Greeting --> Hi @sunw80910! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> The UnicodeDecodeError ('gbk' codec) happens because the `generate_docker_compose` script reads files like `.env.example` and `docker-compose-template.yaml` without specifying an encoding, so Python defaults to your system locale (often 'gbk' on Chinese Windows systems). If these files contain UTF-8 characters, this causes the error. To fix this: 1. Make sure all your `.env`, `.env.example`, and `docker-compose-template.yaml` files are saved as UTF-8 (without BOM). 2. Run the script in an environment where the locale is set to UTF-8. For Docker, set `LANG` and `LC_ALL` to `C.UTF-8` (or `en_US.UTF-8` if `C.UTF-8` isn't available), and `PYTHONIOENCODING=utf-8` in your Dockerfile or Compose file. This is now the recommended setting and is used in recent Dify versions ([PR #30621](https://github.com/langgenius/dify/pull/30621)). 3. As a local workaround, you can edit the `generate_docker_compose` script and add `encoding="utf-8"` to all `open()` calls. This issue is discussed in [existing issues and docs](https://github.com/langgenius/dify/issues/22436), and the root cause is the missing encoding argument in the script ([see code](https://github.com/langgenius/dify/blob/aa68966b5558699aaf8aace94402498fa697d776/docker/generate_docker_compose#L7-L74)). Proper locale and encoding settings in Docker are critical to avoid these errors. <!-- 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/79ca3f10-dd66-4451-8563-c15a592e1943?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/79ca3f10-dd66-4451-8563-c15a592e1943?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/79ca3f10-dd66-4451-8563-c15a592e1943?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/79ca3f10-dd66-4451-8563-c15a592e1943?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/79ca3f10-dd66-4451-8563-c15a592e1943?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/79ca3f10-dd66-4451-8563-c15a592e1943?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/79ca3f10-dd66-4451-8563-c15a592e1943?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%20UnicodeDecodeError%20%28%27gbk%27%20codec%29%20happens%20because%20the%20%60generate_docker_compose%60%20script%20reads%20files%20like%20%60.env.example%60%20and%20%60docker-compose-template.yaml%60%20without%20specifying%20an%20encoding%2C%20so%20Python%20defaults%20to%20your%20system%20locale%20%28often%20%27gbk%27%20on%20Chinese%20Windows%20systems%29.%20If%20these%20files%20contain%20UTF-8%20characters%2C%20this%20causes%20the%20error.%0A%0ATo%20fix%20this%3A%20%20%0A1.%20Make%20sure%20all%20your%20%60.env%60%2C%20%60.env.example%60%2C%20and%20%60docker-compose-template.yaml%60%20files%20are%20saved%20as%20UTF-8%20%28without%20BOM%29.%0A2.%20Run%20the%20script%20in%20an%20environment%20where%20the%20locale%20is%20set%20to%20UTF-8.%20For%20Docker%2C%20set%20%60LANG%60%20and%20%60LC_ALL%60%20to%20%60C.UTF-8%60%20%28or%20%60en_US.UTF-8%60%20if%20%60C.UTF-8%60%20isn%27t%20available%29%2C%20and%20%60PYTHONIOENCODING%3Dutf-8%60%20in%20your%20Dockerfile%20or%20Compose%20file.%20This%20is%20now%20the%20recommended%20setting%20and%20is%20used%20in%20recent%20Dify%20versions%20%28%5BPR%20%2330621%5D%28https%3A//github.com/langgenius/dify/pull/30621%29%29.%0A3.%20As%20a%20local%20workaround%2C%20you%20can%20edit%20the%20%60generate_docker_compose%60%20script%20and%20add%20%60encoding%3D%22utf-8%22%60%20to%20all%20%60open%28%29%60%20calls.%0A%0AThis%20issue%20is%20discussed%20in%20%5Bexisting%20issues%20and%20docs%5D%28https%3A//github.com/langgenius/dify/issues/22436%29%2C%20and%20the%20root%20cause%20is%20the%20missing%20encoding%20argument%20in%20the%20script%20%28%5Bsee%20code%5D%28https%3A//github.com/langgenius/dify/blob/aa68966b5558699aaf8aace94402498fa697d776/docker/generate_docker_compose%23L7-L74%29%29.%20Proper%20locale%20and%20encoding%20settings%20in%20Docker%20are%20critical%20to%20avoid%20these%20errors.)&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/31351)
Author
Owner

@fatelei commented on GitHub (Jan 21, 2026):

在使用docker部署的时候,修改了.env的部分配置
执行./generate_docker_compose 的时候,发生了报错

change the .env file encoding to utf8

@fatelei commented on GitHub (Jan 21, 2026): > 在使用docker部署的时候,修改了.env的部分配置 > 执行./generate_docker_compose 的时候,发生了报错 change the .env file encoding to utf8
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21816