This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: netrc.__repr__() is broken for writing to file
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Bezier89, methane
Priority: normal Keywords: patch

Created on 2017-06-29 19:12 by Bezier89, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2491 merged Bezier89, 2017-06-29 19:12
PR 4244 merged python-dev, 2017-11-03 00:40
PR 4276 merged sloria, 2017-11-04 12:35
Messages (4)
msg297296 - (view) Author: James (Bezier89) * Date: 2017-06-29 19:12
Have any valid .netrc file. For testing purposes you can use this:

machine abc.xyz login myusername password mypassword

The documentation for netrc.__repr__() states that it "dumps the class data as a string in the format of a netrc file". However, when you try to actually do this, you'll encounter a nasty bug. This can be seen by running the follow commands:

auth = netrc.netrc(os.path.expanduser(r"~\.netrc"))
print(auth.__repr__())

The expected output is:

machine abc.xyz
        login myusername
        password mypassword

The actual output is:

machine abc.xyz
        login 'myusername'
        password 'mypassword'

If you write this back out to the .netrc file, authentication will fail since incorrect username/password (with ' character at beginning at end) will be passed.
msg303398 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-09-30 07:10
New changeset b24cd055ecb3eea9a15405a6ca72dafc739e6531 by INADA Naoki (James Sexton) in branch 'master':
bpo-30806 netrc.__repr__() is broken for writing to file (GH-2491)
https://github.com/python/cpython/commit/b24cd055ecb3eea9a15405a6ca72dafc739e6531
msg305461 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-11-03 05:36
New changeset 5fbe5e161c969bc8a0d44a301152f8bf5afe0fc7 by INADA Naoki (Miss Islington (bot)) in branch '3.6':
bpo-30806: Fix netrc.__repr__() format (GH-2491)
https://github.com/python/cpython/commit/5fbe5e161c969bc8a0d44a301152f8bf5afe0fc7
msg307943 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-12-10 06:10
New changeset 3b9173d33adc2903e1af461214333b0052d7b1e9 by INADA Naoki (Steven Loria) in branch '2.7':
bpo-30806: Fix netrc.__repr__() format (GH-2491)
https://github.com/python/cpython/commit/3b9173d33adc2903e1af461214333b0052d7b1e9
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 74989
2017-12-10 06:10:05methanesetmessages: + msg307943
2017-11-04 12:35:26sloriasetpull_requests: + pull_request4237
2017-11-03 05:37:32methanesetstatus: open -> closed
stage: patch review -> resolved
2017-11-03 05:37:21methanesetresolution: fixed
versions: + Python 3.7
2017-11-03 05:36:48methanesetmessages: + msg305461
2017-11-03 00:40:49python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request4208
2017-09-30 07:10:35methanesetnosy: + methane
messages: + msg303398
2017-06-29 19:12:21Bezier89create