You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
netrc.netrc() emits a syntax error if it encounters a comment after a blank line. Prior to the 3.11, it only did this if the comment was the first non-whitespace thing in the file, but now with 3.11 it does it for all comments.
$ python netrc-test.py Traceback (most recent call last): File "/home/lukeshu/netrc-test.py", line 14, in <module> print(netrc.netrc(filename)) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/netrc.py", line 31, in __init__ self._parse(file, fp, default_netrc) File "/usr/lib/python3.11/netrc.py", line 66, in _parse raise NetrcParseError(netrc.NetrcParseError: bad toplevel token 'HTTP' (netrctest, line 3)
This issue was made worse by #26330. Prior to that change (prior to 3.11), it only triggered on the if the comment was the first thing in the file. For example, if we remove the leading newline:
I recently found out that ~/.netrc files do not officially support comments and even worse, if you add # prefix to a line, netrc will still load that line and attempt to use that entry!
In other cased it might produce a syntax error but the current behavior is clearly messed badly.
Curl itself seems to treat lines prefixed with # as commented, but not python. Python will somehow load them incorrectly. I tried with a github.com entry and while the entry is correct by default and used by github/python to successfully download, once I add # prefix, curl continues to work (using non authenticated calls), python will fail, likely because is sending an incorrect request to github.
Bug report
netrc.netrc()
emits a syntax error if it encounters a comment after a blank line. Prior to the 3.11, it only did this if the comment was the first non-whitespace thing in the file, but now with 3.11 it does it for all comments.For example:
produces
This issue was made worse by #26330. Prior to that change (prior to 3.11), it only triggered on the if the comment was the first thing in the file. For example, if we remove the leading newline:
Before we got:
but now in 3.11 we get:
Your environment
Linked PRs
netrc
module, minor refactor #104511The text was updated successfully, but these errors were encountered: