2011-10-31 3 views
1

NT認証サーバーに接続するのにurllib2python-ntlmを使用しようとしていますが、エラーが発生しています。python-ntlmを使用したIndexError

user = 'DOMAIN\user.name' 
password = 'Password123' 
url = 'http://corporate.domain.com/page.aspx?id=foobar' 

passman = urllib2.HTTPPasswordMgrWithDefaultRealm() 
passman.add_password(None, url, user, password) 
# create the NTLM authentication handler 
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman) 

# create and install the opener 
opener = urllib2.build_opener(auth_NTLM) 
urllib2.install_opener(opener) 

# retrieve the result 
response = urllib2.urlopen(url) 
return response.read() 

そして、ここで私が手にエラーがありますが:

Traceback (most recent call last): 
    File "C:\Python27\test.py", line 112, in get_ntlm_data 
    response = urllib2.urlopen(url) 
    File "C:\Python27\lib\urllib2.py", line 126, in urlopen 
    return _opener.open(url, data, timeout) 
    File "C:\Python27\lib\urllib2.py", line 398, in open 
    response = meth(req, response) 
    File "C:\Python27\lib\urllib2.py", line 511, in http_response 
    'http', request, response, code, msg, hdrs) 
    File "C:\Python27\lib\urllib2.py", line 430, in error 
    result = self._call_chain(*args) 
    File "C:\Python27\lib\urllib2.py", line 370, in _call_chain 
    result = func(*args) 
    File "C:\Python27\lib\site-packages\python_ntlm-1.0.1-py2.7.egg\ntlm\HTTPNtlmAuthHandler.py", line 99, in http_error_401 
    return self.http_error_authentication_required('www-authenticate', req, fp, headers) 
    File "C:\Python27\lib\site-packages\python_ntlm-1.0.1-py2.7.egg\ntlm\HTTPNtlmAuthHandler.py", line 35, in http_error_authentication_required 
    return self.retry_using_http_NTLM_auth(req, auth_header_field, None, headers) 
    File "C:\Python27\lib\site-packages\python_ntlm-1.0.1-py2.7.egg\ntlm\HTTPNtlmAuthHandler.py", line 72, in retry_using_http_NTLM_auth 
    UserName = user_parts[1] 
IndexError: list index out of range 

私が間違ってやっている任意のアイデアをここで私はthe python-ntlm siteから、使用しているコードですか?

+0

私はあきらめ、代わりにカールを使用して終了。 –

+0

この同じ問題を抱えていますが、python_ntlmを使用して泡を使用しています – Rich

答えて

5

試してみてください。

user = r'DOMAIN\user.name' 
+0

これは私のために働いた!ありがとう。 – Rich

+0

これも私のために働いた! @ boubou、これを合格とマークしてください。 – g4ur4v

+0

完全性のために、 'user = 'DOMAIN \\ user.name'も同様に動作します。文字列エスケープは問題だった。そして私はそれが@ ryan-mcgrealであるべきだと思っています。 – Steen

関連する問題