[New-bugs-announce] [issue34908] netrc parding is overly strict

Ian Remmel report at bugs.python.org
Fri Oct 5 13:21:24 EDT 2018


New submission from Ian Remmel <design at ianwremmel.com>:

This started as a bug report for httpie https://github.com/jakubroztocil/httpie/issues/717#issuecomment-426125261

And became a bug report for requests https://github.com/requests/requests/issues/4813

> But turned out to be an issue with Python's netrc parser:
> 
>
> it appears that auth via netrc is broken if ~/.netrc includes entries that are not exactly login/password tuples. For example, I have the following entries for circle ci and heroku:
>
> ```
>    machine api.heroku.com
>      login <redacted>
>      password <redacted>
>      method interactive
>    machine circleci.com
>      login <redacted>
> ```
>
> both of these entries prevent my entry for github.com from working with httpie (but curl works just fine).


I've used the following script to test python 2.7 and 3.7:

```
import netrc
import os.path

netrc.netrc(os.path.expanduser('~/.netrc')).authenticators('api.github.com')
```

Python 2:
```
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    netrc.netrc(os.path.expanduser('~/.netrc')).authenticators('api.github.com')
  File "/usr/local/Cellar/python at 2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/netrc.py", line 35, in __init__
    self._parse(file, fp, default_netrc)
  File "/usr/local/Cellar/python at 2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/netrc.py", line 117, in _parse
    file, lexer.lineno)
netrc.NetrcParseError: bad follower token 'method' (/Users/ian/.netrc, line 7)
````

Python 3:
```
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    netrc.netrc(os.path.expanduser('~/.netrc')).authenticators('api.github.com')
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/netrc.py", line 30, in __init__
    self._parse(file, fp, default_netrc)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/netrc.py", line 111, in _parse
    file, lexer.lineno)
netrc.NetrcParseError: bad follower token 'method' (/Users/ian/.netrc, line 7)
```

----------
messages: 327155
nosy: ianwremmel
priority: normal
severity: normal
status: open
title: netrc parding is overly strict
versions: Python 2.7, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34908>
_______________________________________


More information about the New-bugs-announce mailing list