python urlib2 https身份验证

时间:2014-03-19 14:03:56

标签: python linux

我正在尝试通过带有http身份验证的https来查询群集的API

import os
import subprocess
import sys
import urllib2
import base64

def proc():
    request = urllib2.Request("https://192.168.174.163:9443/restapi/server/api/v2/cluster")
    base64string = base64.encodestring('%s:%s' % ("admin", "admin")).replace('\n', '')
    request.add_header("Authorization", "Basic %s" % base64string)
    result = urllib2.urlopen(request)
    print result



def main():
    proc()


if __name__ == "__main__":
    main()

输出:

/usr/bin/python /home/kshk/PycharmProjects/intelIDH/autoIDH.py
<addinfourl at 3074601484L whose fp = <socket._fileobject object at 0xb740e3ec>>

Process finished with exit code 0

知道我为什么会得到垃圾值?

从命令行开始工作正常......

curl -k -u admin:admin -g https://10.0.20.101:9443/restapi/server/api/v2/cluster

并提供输出

{"dnsresolution":true,"name":"clusterX","acceptlicense":true}

我需要在python中复制这个......任何想法......

0 个答案:

没有答案