def _request(self, url, data, action, content_type):

        if ((data or isinstance(data, dict)) and
            action not in ('GET', 'DELETE',)):
            data = json.dumps(data)
            if action == 'PUT':
                opener = urllib2.build_opener(urllib2.HTTPHandler)
                req = urllib2.Request(url, data=data)
                req.add_header('Content-Type', content_type)
                req.get_method = lambda: 'PUT'
                conn = opener.open(req)
            else:
                headers = {'Content-Type': content_type}
                try:
                    req = urllib2.Request(url, data, headers)
                    conn = urllib2.urlopen(req)
                except TypeError:
                    # This is for the _lights.find bodyless POST.
                    data = urllib.urlencode(data, 1)
                    req = urllib2.Request(url, data, headers)
                    conn = urllib2.urlopen(req)
        elif action == 'DELETE':
            opener = urllib2.build_opener(urllib2.HTTPHandler)
            req = urllib2.Request(url)
            req.get_method = lambda: 'DELETE'
            conn = opener.open(req)
        else:
            req = urllib2.Request(url)
            conn = urllib2.urlopen(req)
        response = conn.read()
        conn.close()
        try:
            content = json.loads(response)
        except:
            content = response
        return conn.info().headers, content
dataset/ETHPy150Open allanbunch/beautifulhue/beautifulhue/libs/http.py/Request._request/original