aboutsummaryrefslogtreecommitdiff
blob: af807c802004b3412f0abe4e9ce16f8640e05b76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import httplib

# json headers for gentoostats-cli
headers = {'Accept': 'application/json'}

def GET(server, url, headers, https=True):
    """
    Get url from server using headers 
    """
    if https:
        conn = httplib.HTTPSConnection(server)
    else:
        conn = httplib.HTTPConnection(server)
    try:
        conn.request('GET', url=url, headers=headers)
        data = conn.getresponse().read()
    except httplib.HTTPException:
        return None
    finally:
        if conn:
            conn.close()
    return data

def deserialize(object):
    """
    Decode json object
    """
    try:
        decoded = json.JSONDecoder().decode(object)
    except (ValueError, TypeError):
        return None
    return decoded