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

How to use auth info from .netrc is not clear #139

Closed
jclem opened this issue Apr 9, 2013 · 6 comments
Closed

How to use auth info from .netrc is not clear #139

jclem opened this issue Apr 9, 2013 · 6 comments

Comments

@jclem
Copy link

jclem commented Apr 9, 2013

The README says "Authorization information from .netrc is honored as well", but it's not clear how this is done. The README should be updated to explain this. I'd submit a PR, but I still can't figure it out. Not quite as easy as curl -n.

@jkbrzt
Copy link
Member

jkbrzt commented Apr 10, 2013

For now, HTTPie always tries to read the default ~/.netrc file (or ~/_netrc on windows). It's actually the underlying python-requests library that does that.

@jclem
Copy link
Author

jclem commented Apr 10, 2013

Hm...I have a ~/.netrc file that works perfectly well with curl, but seems to be completely ignored by HTTPie.

@jkbrzt
Copy link
Member

jkbrzt commented Apr 10, 2013

Here is a working example:

Without ~/.netrc:

$ http httpbin.org/basic-auth/httpie/test
HTTP/1.1 401 UNAUTHORIZED
Connection: close
Content-Length: 0
Date: Wed, 10 Apr 2013 16:49:10 GMT
Server: gunicorn/0.16.1
Www-Authenticate: Basic realm="Fake Realm"

Added this to ~/.netrc:

machine httpbin.org
login httpie
password test

And it's picked up:

$ http httpbin.org/basic-auth/httpie/test
HTTP/1.1 200 OK
Connection: close
Content-Length: 47
Content-Type: application/json
Date: Wed, 10 Apr 2013 16:49:23 GMT
Server: gunicorn/0.16.1

{
    "authenticated": true, 
    "user": "httpie"
}

You can also set the --verbose flag to see if HTTPie sends Authorization: Basic xxxxxx.

@jkbrzt
Copy link
Member

jkbrzt commented Apr 10, 2013

Actually, you can run $ python -m netrc to see how your ~/.netrc is understood by he netrc module from Python's standard library.

capncodewash pushed a commit to capncodewash/httpie that referenced this issue Apr 17, 2013
@capncodewash
Copy link

I've opened a pull request to modify the readme with a short example of this.

@jkbrzt jkbrzt closed this as completed in d1b91bf Apr 17, 2013
@jclem
Copy link
Author

jclem commented Aug 14, 2013

Just to follow up, I had no value next to one of the login fields in my .netrc that seemed only to bother Python. curl for some reason did not have a problem with it.

proinsias added a commit to proinsias/dotfiles that referenced this issue Jan 11, 2019
I was having trouble with installing bashhub. Turns out that my .netrc
had the wrong permissions and had a comment. Fixed these issues and
bashhub now installs.

The command I got from
[GitHub](httpie/cli#139) to explore this
was:

	python -m .netrc
proinsias added a commit to proinsias/dotfiles that referenced this issue Jan 11, 2019
I was having trouble with installing bashhub. Turns out that my .netrc
had the wrong permissions and had a comment. Fixed these issues and
bashhub now installs.

The command I got from
[GitHub](httpie/cli#139) to explore this
was:

	python -m .netrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants