def execute(self, query, params=None, **kwargs): """Execute YQL query""" query = clean_query(query) url = self.get_uri(query, params, **kwargs) # Just in time change to https avoids # invalid oauth sigs if self.scheme == HTTPS_SCHEME: url = url.replace(HTTP_SCHEME, HTTPS_SCHEME) yql_logger.debug("executed url: %s", url) http_method = get_http_method(query) if http_method in ["DELETE", "PUT", "POST"]: data = {"q": query} # Encode as json and set Content-Type header # to reflect we are sending JSON # Fixes LP: 629064 data = json.dumps(data) headers = {"Content-Type": "application/json"} resp, content = self.http.request(url, http_method, headers=headers, body=data) yql_logger.debug("body: %s", data) else: resp, content = self.http.request(url, http_method) yql_logger.debug("http_method: %s", http_method) if resp.get('status') == '200': return YQLObj(json.loads(content)) else: raise YQLError, (resp, content)
def execute(self, query, params=None, **kwargs): """Execute YQL query""" query = clean_query(query) url = self.get_uri(query, params, **kwargs) # Just in time change to https avoids # invalid oauth sigs if self.scheme == HTTPS_SCHEME: url = url.replace(HTTP_SCHEME, HTTPS_SCHEME) yql_logger.debug("executed url: %s", url) http_method = get_http_method(query) if http_method in ["DELETE", "PUT", "POST"]: data = {"q": query} # Encode as json and set Content-Type header # to reflect we are sending JSON # Fixes LP: 629064 data = json.dumps(data) headers = {"Content-Type": "application/json"} resp, content = self.http.request( url, http_method, headers=headers, body=data) yql_logger.debug("body: %s", data) else: resp, content = self.http.request(url, http_method) yql_logger.debug("http_method: %s", http_method) if resp.get('status') == '200': return YQLObj(json.loads(content)) else: raise YQLError, (resp, content)
def __init__(self, query): self.query = clean_query(query)