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

Created on 2017-06-29 19:12 by Bezier89, last changed 2017-09-30 07:10 by inada.naoki.

Pull Requests
URL Status Linked Edit
PR 2491 merged Bezier89, 2017-06-29 19:12
Messages (2)
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 (inada.naoki) * (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
History
Date User Action Args
2017-09-30 07:10:35inada.naokisetnosy: + inada.naoki
messages: + msg303398
2017-06-29 19:12:21Bezier89create