genericREST.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:aci 作者: cpaggen 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号