def getAPICCookie(ip_addr, authheader, username, password):
url = 'http://'+ip_addr+'/api/aaaLogin.xml'
# create 'opener' (OpenerDirector instance)
opener = urllib2.build_opener(*handlers)
# Install the opener.
# Now all calls to urllib2.urlopen use our opener.
urllib2.install_opener(opener)
http_header["Host"]=ip_addr
xml_string = "<aaaUser name='%s' pwd='%s'/>" % (username, password)
req = urllib2.Request(url=url, data=xml_string, headers=http_header)
try:
response = urllib2.urlopen(req)
except urllib2.URLError, e:
print 'Failed to obtain auth cookie: %s' % (e)
return 0
else:
rawcookie=response.info().getheaders('Set-Cookie')
return rawcookie[0]
评论列表
文章目录