我试图测试与Nexus服务器的交互,该服务器需要对我打算使用的操作进行身份验证,但我还需要处理内部代理服务器。使用httplib2处理身份验证和代理服务器
基于我(有限)的理解,我可以添加多个处理程序的开罐器。不过,我仍然收到了401回应。我检查了用户名和密码是否有效。我不确定是否需要cookie来做到这一点,如果是的话,他们将如何包含它们。 有什么建议吗?
baseUrl = 'server:8070/nexus-webapp-1.3.3/service/local'
params = {"[key]":"[value]"}
data = urllib.urlencode(params)
# create a password manager
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
# Add the username and password as supplied
password_mgr.add_password(None, baseUrl, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
proxy_support = urllib2.ProxyHandler({})
# create "opener" (OpenerDirector instance)
opener = urllib2.build_opener(proxy_support, handler)
urllib2.install_opener(opener)
txheaders = {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
req = Request(protocol+url, data, txheaders)
handle = urlopen(req)
这是导致URLError的头字段:
>HTTPMessage: Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=B4BD05C9582F7B27495CBB675A339724; Path=/nexus-webapp-1.3.3
WWW-Authenticate: NxBASIC realm="Sonatype Nexus Repository Manager API"
Content-Type: text/html;charset=utf-8
Content-Length: 954
Date: Fri, 03 Jul 2009 17:38:42 GMT
Connection: close
更新 看来的Nexus实施Restlet's AuthenticationHelper的定制版本。感谢Alex,我知道该找什么。
谢谢亚历克斯,更新了问题 – 2009-07-03 17:41:04