Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 597: netrc uses locale encoding. #87899

Closed
methane opened this issue Apr 5, 2021 · 3 comments
Closed

PEP 597: netrc uses locale encoding. #87899

methane opened this issue Apr 5, 2021 · 3 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir

Comments

@methane
Copy link
Member

methane commented Apr 5, 2021

BPO 43733
Nosy @methane, @zhangyangyu
PRs
  • bpo-43733: netrc try to use UTF-8 before using locale encoding. #25781
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-05-02.05:01:22.264>
    created_at = <Date 2021-04-05.12:46:50.522>
    labels = ['library', '3.10']
    title = 'PEP 597: netrc uses locale encoding.'
    updated_at = <Date 2021-05-02.05:01:22.264>
    user = 'https://github.com/methane'

    bugs.python.org fields:

    activity = <Date 2021-05-02.05:01:22.264>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-05-02.05:01:22.264>
    closer = 'methane'
    components = ['Library (Lib)']
    creation = <Date 2021-04-05.12:46:50.522>
    creator = 'methane'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43733
    keywords = ['patch']
    message_count = 3.0
    messages = ['390232', '391043', '392667']
    nosy_count = 2.0
    nosy_names = ['methane', 'xiang.zhang']
    pr_nums = ['25781']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43733'
    versions = ['Python 3.10']

    @methane
    Copy link
    Member Author

    methane commented Apr 5, 2021

    with open(file) as fp:

    Can we change the encoding="utf-8" and errors="replace"?

    IMHO, comments are source of UnicodeDecodeError. So we can open file with binary mode and skip comments without decoding it.
    But we need to decode non-comment lines lines with some encoding anyway.

    @methane methane added 3.10 only security fixes stdlib Python modules in the Lib dir labels Apr 5, 2021
    @methane
    Copy link
    Member Author

    methane commented Apr 14, 2021

    I googled "netrc UnicodeDecodeError". It is very rare, but I found two cases.

    ---

    There are several options:

    • Use UTF-8. If user encountered UnicodeDecodeError, user need to change the .netrc encoding.
    • Use UTF-8 with "surrogateescape" or "replace" error handler. non-UTF-8 in comments are ignored.
    • Use latin-1. non-ASCII characters in comments are ignored.

    @methane
    Copy link
    Member Author

    methane commented May 2, 2021

    New changeset fd0bc7e by Inada Naoki in branch 'master':
    bpo-43733: netrc try to use UTF-8 before using locale encoding. (GH-25781)
    fd0bc7e

    @methane methane closed this as completed May 2, 2021
    @methane methane closed this as completed May 2, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant