コード例 #1
0
def get_sliver_info_from_API():

    sliver_info = []
    request = urllib2.Request('http://127.0.0.1/confine/api/node/')
    response = None
    try:
        response = urllib2.urlopen(request)
    except:
        response = None

    if (response is None):
        return None

    print "Response: " + str(response)
    page = json.loads(response.read())

    for sliver in page['slivers']:
        try:
            response = urllib2.urlopen(urllib2.Request(sliver['uri']))
        except:
            response = None

        if response:
            sliver_info.append(
                common.parse_api_sliver(json.loads(response.read())))

    #print sliver_info
    return sliver_info
コード例 #2
0
ファイル: utils.py プロジェクト: confine-project/confine-dist
def get_sliver_info_from_API():

    sliver_info = []
    request = urllib2.Request("http://127.0.0.1/confine/api/node/")
    response = None
    try:
        response = urllib2.urlopen(request)
    except:
        response = None

    if response is None:
        return None

    print "Response: " + str(response)
    page = json.loads(response.read())

    for sliver in page["slivers"]:
        try:
            response = urllib2.urlopen(urllib2.Request(sliver["uri"]))
        except:
            response = None

        if response:
            sliver_info.append(common.parse_api_sliver(json.loads(response.read())))

    # print sliver_info
    return sliver_info
コード例 #3
0
def get_sliver_info_from_API():

        sliver_info = []
        request = urllib2.Request('http://127.0.0.1/confine/api/node/')
        response= None
        try:
            response = urllib2.urlopen(request)
        except:
            response = None


        if(response is None):
            return None

       # print "Response: "+ str(response.read().replace('\r\n', '\\r\\n')) Do not print this!!! response.read() removes the elements. reading again will return no value
        #ignore UTF8 invalid characters
        value = unicode(str(response.read()), errors='ignore')
        print value
        page = json.loads(value)

        for sliver in page['slivers']:
            try:
                response = urllib2.urlopen(urllib2.Request(sliver['uri']))
            except:
                response = None

            if response:
                #ignore UTF8 invalid characters
                value = unicode(str(response.read()), errors='ignore')
                sliver_info.append(common.parse_api_sliver(json.loads(value)))

        return sliver_info