Esempio n. 1
0
    def request(self, url, method, params):
        if method not in ('GET', 'POST'):
            raise ArgumentError("method must be 'POST' or 'GET'")

        parse_result = urlparse(url)
        host = parse_result.hostname
        port = parse_result.port
        path = parse_result.path

        if parse_result.scheme == 'http':
            conn = httplib.HTTPConnection(host, port=port)
        else:
            conn = httplib.HTTPSConnection(host, port=port)

        try:
            req_url = path
            body = None
            headers = {}
            if method == 'GET':
                req_url = req_url + '?' + urllib.urlencode(params)
            else:
                body = urllib.urlencode(params)
                headers = {"Content-type": "application/x-www-form-urlencoded"}

            log.debug("[httplib] request url: %s, method: %s params: %s" % (url, method, params))
            conn.request(method, req_url, body, headers)
            response = conn.getresponse()
            http_status = response.status
            http_body = response.read()
            log.debug("[httplib] response status: %s body: %s" % (http_status, http_body))
        except httplib.HTTPException, e:
            raise HTTPError("httplib request exception: %s" % e.message)
Esempio n. 2
0
 def test_query(self):
     q = SimpleQuery()
     stmt = q.query_by_keyword('Kobe').\
         add_sort('name').\
         add_sort('age', False).\
         distinct_by_unique('score').\
         filter_by('steal', '>', 2).\
         build()
     log.debug(stmt)
Esempio n. 3
0
    def request(self, url, method, params):
        if method not in ('GET', 'POST'):
            raise ArgumentError("method must be 'POST' or 'GET'")

        try:
            log.debug("[requests] request url:%s method: %s params:%s" % (url, method, params))
            if method == 'GET':
                r = requests.get(url, params=params)
            else:
                r = requests.post(url, data=params)
            log.debug("[requests] response data:" + r.text)
        except requests.HTTPError, e:
            raise HTTPError("requests get exception: %s" % e.message)