def request(self, method, url, params=None):
        body = None
        if params:
            if method == 'GET':
                url = '{path}?{params}'.format(path=url,
                                               params=urlencode(params))
            else:
                body = urlencode(params)
        debug('GET {0} HTTP/1.1'.format(url))

        def _request():
            self.http.request(method, url, body, headers=self._headers)
            return self.http.getresponse()

        try:
            try:
                r = _request()
            except (CannotSendRequest, BadStatusLine), e:
                debug('exception {0}, reconnecting...'.format(e))
                self.http.close()
                self.http.connect()
                r = _request()
        except HTTPException, e:
            self.http.close()
            raise NetworkError('HTTP request error: {0}'.format(
                    type(e).__name__))
        except socket.gaierror:
            msg = 'cannot get network address for "{host}"'.format(
                    host=self.http.host)
            raise NetworkError(msg)
        except socket.error, e:
            self.http.close()
            raise NetworkError(e.args[1])

        status_msg = '{status} {reason}'.format(status=r.status,
                                                reason=r.reason)
        debug('HTTP/1.1 {0}'.format(status_msg))
        if r.status // 100 != 2:
            self.http.close()
            raise NetworkError('server error: {0}'.format(status_msg))

        try:
            data = r.read().decode(NETWORK_ENCODING)
            res = json.loads(data)
            debug('response in JSON\n{msg}'.format(
                msg=json.dumps(res, ensure_ascii=False, indent=4)))
            return res
        except __HOLE__:
            raise NetworkError('bad server response: {0}'.format(data))
dataset/ETHPy150Open vlasovskikh/convoread/convoread/convore.py/Connection.request