请教一下大家,有没有人成功做过urllib2的http authentication.

31 views
Skip to first unread message

Rocket Yang

unread,
Aug 23, 2012, 12:44:41 AM8/23/12
to zp...@googlegroups.com
我用urllib2做http的认证,一直无法成功。服务器的返回的header里面包含
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
这两个认证策略

相关的代码:

'''
Created on Aug 23, 2012

@author: rocket
'''
import urllib2

if __name__ == '__main__':

theurl = 'http://192.168.0.96'

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
# this creates a password manager
passman.add_password(None, theurl, 'rocketyang', '123456')
# because we have put None at the start it will always
# use this username/password combination for urls
# for which `theurl` is a super-url

authhandler = urllib2.HTTPBasicAuthHandler(passman)
# create the AuthHandler

opener = urllib2.build_opener(authhandler)

urllib2.install_opener(opener)
pagehandle = urllib2.urlopen(theurl)
# authentication is now handled automatically for us

Zoom.Quiet

unread,
Aug 23, 2012, 12:52:37 AM8/23/12
to Python.cn@google, zp...@googlegroups.com
技术讨论汇集到 CPyUG 的吧,,,

2012/8/23 Rocket Yang <rocke...@gmail.com>:

> --
> '''邮件来自 `ZPyUG`--珠三角地区Python用户组 列表
> 详情: https://groups-beta.google.com/group/zpug
> 发言: zp...@googlegroups.com
> 退订: zpug-uns...@googlegroups.com
> 维基: http://wiki.woodpecker.org.cn/moin/ZPyUG
> 中国事务: https://groups.google.com/group/CPUG
> 北京事务: https://groups.google.com/group/bpug
> 上海事务: https://groups.google.com/group/spug
> 安徽事务: https://groups.google.com/group/ahpug
> 东南事务: https://groups.google.com/group/cpug-eastchina
> 技术列表: https://groups.google.com/group/python-cn
> '''

--
人生苦短, Pythonic! 冗余不做,日子甭过!备份不做,十恶不赦!
俺: http://about.me/zoom.quiet
文字协议: http://creativecommons.org/licenses/by-sa/2.5/cn/

Reply all
Reply to author
Forward
0 new messages