Skip to content
This repository was archived by the owner on Nov 20, 2026. It is now read-only.
This repository was archived by the owner on Nov 20, 2026. It is now read-only.

docs: use explicit UTF-8 encoding in redirect generation script #7749

Open

Description

@wkd09

What is the doc issue?

Describe the issue

python/docs/redirects/redirects.py reads and writes redirect-related files without specifying an explicit encoding.

The script currently reads redirect_template.html and redirect_urls.txt, then writes generated redirect index.html files using Python's default system encoding.

This is probably fine in most environments, but on some Windows locales where the default encoding is not UTF-8, the script could fail with a UnicodeDecodeError or UnicodeEncodeError if the files contain non-ASCII characters.

This is more of a docs tooling portability issue than a runtime bug.

What do you want to see in the doc?

I think python/docs/redirects/redirects.py should explicitly use encoding="utf-8" when reading and writing text files.

Suggested change:

HTML_REDIRECT_TEMPLATE = HTML_PAGE_TEMPLATE_FILE.open("r", encoding="utf-8").read()

with open(redirect_page_path, "w", encoding="utf-8") as f:
    f.write(redirect_page)

with open(REDIRECT_URLS_FILE, "r", encoding="utf-8") as f:
    lines = f.readlines()

Link to the doc page, if applicable

https://github.com/microsoft/autogen/blob/main/python/docs/redirects/redirects.py

Activity

  1. reallyticsai commented on May 29, 2026

    @reallyticsai

    Sure, let's address this. We've seen similar issues in the past where explicit encoding can prevent unexpected errors, especially on different operating systems. Here's what we can do:

    1. Explicit Encoding: We should explicitly set the encoding to utf-8 for both reading and writing files. This ensures that the script works consistently across different environments.

    2. Code Example: Here's how you can modify the script:

    HTML_REDIRECT_TEMPLATE = HTML_PAGE_TEMPLATE_FILE.open("r", encoding="utf-8").read()
    
    with open(redirect_page_path, "w", encoding="utf-8") as f:
        f.write(redirect_page)
    
    with open(REDIRECT_URLS_FILE, "r", encoding="utf-8") as f:
        lines = f.readlines()
    1. Testing: After making these changes, it's crucial to test the script in different locales to ensure it handles non-ASCII characters correctly.

    2. Documentation: Update the doc to reflect these changes and explain why explicit encoding is important.

    By making these adjustments, we can avoid potential runtime errors and ensure the script runs smoothly across various locales.

  2. wkd09 commented on May 29, 2026

    @wkd09
    Author

    Thanks for the suggestion.

    I agree that explicitly setting encoding="utf-8" is important to avoid platform-dependent issues across different OS locales.

    I’ve already opened PR #7750 to address this by applying explicit UTF-8 encoding to the relevant read/write operations in redirects.py. Please let me know if any additional tests or documentation updates are needed.

  3. added a commit that references this issue on Jun 7, 2026
    9e22500
  4. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    I'd like to take this one (docs: use explicit UTF-8 encoding in redirect generation scr). I'll dig into the root cause and follow up with a PR shortly. (claiming via Stella (@LeonxLJX))

  5. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    I'd like to take this one (docs: use explicit UTF-8 encoding in redirect generation scr). I'll look into the root cause and follow up with a PR. (claiming via Stella (@LeonxLJX))

  6. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    Hi! I'd like to add explicit UTF-8 encoding in the redirect generation script. Trivial fix. May I be assigned?

  7. added 2 commits that reference this issue on Sep 2, 2026
    def3edf
    edcca7f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions