Open
Description
I have an error 401 when I try to connect to https://xxxxx.fr/ews/exchange.asmx. It works with curl (or pycurl) but not with requests-ntlm. Thank you for your answer!
$ pip freeze | grep requests
requests==2.8.1
requests-ntlm==0.2.0
Curl:
#$DATA contains the xml in the python code
curl -s -u USERNAME:XXXX:XXXX -L https://xxxxx.fr/ews/exchange.asmx -d "$DATA" -H "Content-Type:text/xml" --ntlm
Python:
import requests
from requests_ntlm import HttpNtlmAuth
url = 'https://xxxxx.fr/ews/exchange.asmx'
username = 'DOMAIN.fr\\USERNAME'
password = 'XXXX:XXXX'
headers = {'Content-Type': 'text/xml'}
data = '''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Body>
<ResolveNames xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
ReturnFullContactData="true">
<UnresolvedEntry>USERNAME</UnresolvedEntry>
</ResolveNames>
</soap:Body>
</soap:Envelope>
'''
response = requests.get(url, data=data, headers=headers, auth=HttpNtlmAuth(username, password))
print response
Python output:
<Response [401]>
TCPdump output:
sudo tcpdump -q
18:04:46.885156 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:46.933064 IP xxxxx.fr.https > home.54023: tcp 0
18:04:46.933192 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:46.946482 IP home.54023 > xxxxx.fr.https: tcp 517
18:04:46.982548 IP xxxxx.fr.https > home.54023: tcp 0
18:04:46.987380 IP xxxxx.fr.https > home.54023: tcp 1440
18:04:46.989147 IP xxxxx.fr.https > home.54023: tcp 1440
18:04:46.989217 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:46.989381 IP ixxxxx.fr.https > home.54023: tcp 1151
18:04:46.989442 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:46.993091 IP home.54023 > xxxxx.fr.https: tcp 214
18:04:47.035220 IP xxxxx.fr.https > home.54023: tcp 107
18:04:47.035350 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:47.035999 IP home.54023 > xxxxx.fr.https: tcp 949
18:04:47.075558 IP xxxxx.fr.https > home.54023: tcp 533
18:04:47.075653 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:47.077615 IP home.54023 > xxxxx.fr.https: tcp 1045
18:04:47.117239 IP xxxxx.fr.https > home.54023: tcp 789
18:04:47.117317 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:47.180575 IP home.54023 > xxxxx.fr.https: tcp 1301
18:04:47.221738 IP xxxxx.fr.https > home.54023: tcp 341
18:04:47.221816 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:47.223726 IP home.54023 > xxxxx.fr.https: tcp 0
18:04:47.260520 IP xxxxx.fr.https > home.54023: tcp 0
18:04:47.260641 IP home.54023 > xxxxx.fr.https: tcp 0
Activity
Lukasa commentedon Nov 15, 2015
There doesn't appear to be any auth traffic there at all. Can you print
response.headers
for me please?response.history
as well, if possible.jeeberhardt commentedon Nov 15, 2015
Here it is !
Lukasa commentedon Nov 15, 2015
Hmm, you seem to be struggling to auth with NTLM. NTLM is a fairly tricky auth method. Can you also run:
jeeberhardt commentedon Nov 15, 2015
Classic Microsoft ...
Lukasa commentedon Nov 15, 2015
So that's a real NTLM auth challenge. Working out why this isn't working is really going to be quite tricky, I'm afraid. =(
Out of interest, does curl work out your NTLM domain? Do you want to try removing it from the requests case, and having your username just be
USERNAME
?jeeberhardt commentedon Nov 15, 2015
yeah ... I think so, too. ^^
But thank you for your time, it is not your fault if NTLM is a little bit shitty. I tried with urllib2, and it doesn't eitheir. At the end, I will keep my (ugly) subprocess functions with curl.
Yes, it does. If I am just using my
USERNAME
, curl is still working. (Is it what you asked?)Lukasa commentedon Nov 15, 2015
@jeeberhardt Does it work with requests?
jeeberhardt commentedon Nov 15, 2015
Nope, if remove the
DOMAIN\\
fromDOMAIN\\USERNAME
and just keepUSERNAME
, I have this error:But if I keep
\\USERNAME
, I have this:Is it what you wanted ?
Lukasa commentedon Nov 15, 2015
Nope, 501 suggests that the server doesn't like that at all. Hmm, I'm currently out of ideas for how best to debug this I'm afraid. =(
jeeberhardt commentedon Nov 15, 2015
Argh ... or maybe because of a special character in the password ?
Lukasa commentedon Nov 16, 2015
That's certainly possible!
jeeberhardt commentedon Nov 16, 2015
Apparently not, I just changed it and ... nothing ! So thank you again, I will stay with
subprocess + curl
.jhoxx commentedon Dec 16, 2015
Hi Cory,
I am having exactly same problem and I believe that it is cased by forcing authentication to NTLM_v2 only. Is there anything we can do with it ?
thanks
J.
Lukasa commentedon Dec 16, 2015
@jhoxx I'm not sure I fully understand that question.
jhoxx commentedon Dec 16, 2015
I tried to authenticate to IIS service via requests-ntlm, but it gave me a 401 repsponse. I can see the request on server, with error message pointing to "wrong passwords". This usually happens when authentication is made by NTLM version 1. Thus I would like to know if there is any way how to enforce requests-ntlm to use NTLM v2 protocol only.
J.
17 remaining items