From e6c691d2e53cbe1f91c3c16e20bd845c177e8cca Mon Sep 17 00:00:00 2001 From: Matt Hickford Date: Mon, 2 Sep 2013 18:23:13 +0100 Subject: [PATCH 1/2] New --auth-type NTLM per https://github.com/jkbr/httpie/issues/76 --- README.rst | 7 +++---- httpie/cli.py | 2 +- httpie/client.py | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index de45f00d8f..237596bded 100644 --- a/README.rst +++ b/README.rst @@ -458,8 +458,7 @@ Any of the default headers can be overwritten. Authentication ============== -The currently supported authentication schemes are Basic and Digest (more to -come). There are two flags that control authentication: +The currently supported authentication schemes are Basic, Digest and NTLM (requires the `requests-ntlm `_ library). There are two flags that control authentication: =================== ====================================================== ``--auth, -a`` Pass a ``username:password`` pair as @@ -472,8 +471,8 @@ come). There are two flags that control authentication: have higher priority). ``--auth-type`` Specify the auth mechanism. Possible values are - ``basic`` and ``digest``. The default value is - ``basic`` so it can often be omitted. + ``basic``, ``digest`` and ``NTLM``. The default value + ``basic`` so it can often be omitted. =================== ====================================================== diff --git a/httpie/cli.py b/httpie/cli.py index 88859dfdb7..0806f2e5cc 100644 --- a/httpie/cli.py +++ b/httpie/cli.py @@ -383,7 +383,7 @@ def _split_lines(self, text, width): auth.add_argument( '--auth-type', - choices=['basic', 'digest'], + choices=['basic', 'digest', 'NTLM'], default='basic', help=""" The authentication mechanism to be used. Defaults to "basic". diff --git a/httpie/client.py b/httpie/client.py index 683b95351d..1af545cbb2 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -69,10 +69,18 @@ def get_requests_kwargs(args): credentials = None if args.auth: - credentials = { - 'basic': requests.auth.HTTPBasicAuth, - 'digest': requests.auth.HTTPDigestAuth, - }[args.auth_type](args.auth.key, args.auth.value) + if args.auth_type == 'basic': + credentials = requests.auth.HTTPBasicAuth(args.auth.key, args.auth.value) + elif args.auth_type == 'digest': + credentials = requests.auth.HTTPDigestAuth(args.auth.key, args.auth.value) + elif args.auth_type == 'NTLM': + try: + from requests_ntlm import HttpNtlmAuth + except ImportError: + print "Please install the requests-ntlm library from https://github.com/requests/requests-ntlm" + raise + credentials = HttpNtlmAuth(args.auth.key, args.auth.value) + kwargs = { 'stream': True, From 8cf0426c75d8a3794bd7ccdf0e868c345e190fd8 Mon Sep 17 00:00:00 2001 From: Matt Hickford Date: Sat, 7 Sep 2013 15:41:29 +0100 Subject: [PATCH 2/2] fix python 3 compatibility problem --- httpie/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpie/client.py b/httpie/client.py index 1af545cbb2..77f16d5f17 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -77,7 +77,7 @@ def get_requests_kwargs(args): try: from requests_ntlm import HttpNtlmAuth except ImportError: - print "Please install the requests-ntlm library from https://github.com/requests/requests-ntlm" + sys.stderr.write("Please install the requests-ntlm library from https://github.com/requests/requests-ntlm") raise credentials = HttpNtlmAuth(args.auth.key, args.auth.value)