def _do_call(self, http_method, url, parameters, auth_handlers,
            content_type, parse_json):

        headers, auth_params = HttpUtils.handle_authentication(auth_handlers)
        parameters.update(auth_params)
        if parse_json:
            headers["Accept"] = "application/json"

        headers.update(UrlUtils.generate_client_headers())

        data = None
        opener = HttpUtils.get_http_opener(content_type)
        if (http_method == "GET"):
            url = UrlUtils.build_url_with_query_string(url, parameters)
        else:
            data, additional_headers = HttpUtils.build_data_for_content_type(
                    content_type, parameters, headers)
            headers.update(additional_headers)

        request = urllib2.Request(url, data, headers)
        request.get_method = lambda: http_method
        try:
            response = opener.open(request)
        except urllib2.HTTPError, e:
            if e.getcode() == 500:
                response = e
            else:
                import sys
                raise MashapeClientException("Error executing the request "
                    + str(sys.exc_info()[1]))
Exemplo n.º 2
0
	def _do_call(self, http_method, url, parameters, has_mashape_auth, public_key, private_key, parse_json):
		if parameters == None:
			parameters = {};
		else:
			for key in parameters.keys():
				if parameters[key] == None:
					parameters.pop(key)
		
		parsedUrl = urlparse(url)
		parameters.update(UrlUtils.get_query_string_parameters(parsedUrl.query))

		headers = {"Content-type": "application/x-www-form-urlencoded"}
		if parse_json:
			headers["Accept"] = "application/json"

		headers.update(UrlUtils.generate_client_headers())
		if has_mashape_auth:
			headers.update(AuthUtils.generate_authentication_header(public_key, private_key))
			
		# if you have SSL issues (invalid certificate), try:
		# h = httplib2.Http(disable_ssl_certificate_validation=True) 
#		h = httplib.Http()
		qpos = url.find("?")
		if ( qpos > 0 ):
			url = url[:qpos]
		url = UrlUtils.replace_base_url_parameters(url, parameters)

		params = urllib.urlencode(parameters)
		request = urllib2.Request(url, params, headers)
		if (http_method == "GET"):
			url += "?" + params
			request = urllib2.Request(url, None, headers)
		opener = urllib2.build_opener(urllib2.HTTPHandler)
		request.get_method = lambda: http_method
		try:
			responseValue = opener.open(request).read()
		except:
			import sys
			raise MashapeClientException("Error executing the request " + str(sys.exc_info()[1]), 2000)

		responseJson = None
		if responseValue != None and parse_json:
			responseJson = json.loads(unicode(responseValue, errors='replace'))
			return responseJson
		else:
			return responseValue
	def _do_call(self, url, httpMethod, token, parameters):
		if parameters == None:
			parameters = {};
		else:
			for key in parameters.keys():
				if parameters[key] == None:
					parameters.pop(key)
		
		parameters[ModuleInfo.TOKEN] = token
		parameters[ModuleInfo.LANGUAGE] = ModuleInfo.CLIENT_LIBRARY_LANGUAGE;
		parameters[ModuleInfo.VERSION] = ModuleInfo.CLIENT_LIBRARY_VERSION;
		
		parsedUrl = urlparse(url)
		parameters.update(UrlUtils.get_query_string_parameters(parsedUrl.query))

		headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
		
		# if you have SSL issues (invalid certificate), try:
		# h = httplib2.Http(disable_ssl_certificate_validation=True) 
		h = httplib2.Http()
		qpos = url.find("?")
		if ( qpos > 0 ):
			url = url[:qpos]
		url = UrlUtils.replace_base_url_parameters(url, parameters)

		params = urllib.urlencode(parameters)
		if (httpMethod == "GET"):
			url += "?" + params
		try:
			response, responseValue = h.request(url, httpMethod, params, headers=headers)
		except:
			import sys
			raise MashapeClientException("Error executing the request " + str(sys.exc_info()[1]), 2000)
		responseJson = None
		if responseValue != None and response.status == 200:
			responseJson = json.loads(responseValue)
		return responseJson
Exemplo n.º 4
0
  def _do_call(self, http_method, url, parameters, has_mashape_auth, public_key, private_key):
    if parameters == None:
      parameters = {};
    else:
      for key in parameters.keys():
        if parameters[key] == None:
          parameters.pop(key)
    
    parsedUrl = urlparse(url)
    parameters.update(UrlUtils.get_query_string_parameters(parsedUrl.query))

    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "application/json"}
    headers.update(UrlUtils.generate_client_headers())
    if has_mashape_auth:
      headers.update(AuthUtils.generate_authentication_header(public_key, private_key))
      
    # if you have SSL issues (invalid certificate), try:
    # h = httplib2.Http(disable_ssl_certificate_validation=True) 
    h = httplib2.Http()
    qpos = url.find("?")
    if ( qpos > 0 ):
      url = url[:qpos]
    url = UrlUtils.replace_base_url_parameters(url, parameters)

    params = urllib.urlencode(parameters)
    if (http_method == "GET"):
      url += "?" + params
    opener = urllib2.build_opener(urllib2.HTTPHandler)
    request = urllib2.Request(url, params, headers)
    request.add_header('Content-Type', 'application/json')
    request.get_method = lambda: http_method
    responseValue = opener.open(request).read()
    responseJson = None
    if responseValue != None :
      responseJson = json.loads(responseValue)
    return responseJson