Beispiel #1
0
 def __get_error_from_response(self, json_data):
     if "error" in json_data:
         if json_data["error"] == "Unauthorized":
             return UnauthorizedError(json_data["error_description"])
     error_type = json_data.get("Type")
     error_message = json_data.get(
         "Message", "Error occurred on " + sys._getframe(1).f_code.co_name)
     if error_type == "Invalid Request":
         return InvalidRequestError(error_message)
     else:
         return HEREError(error_message)
Beispiel #2
0
 def __get(self, data):
     url = Utils.build_url(self._base_url, extra_params=data)
     response = requests.get(url, timeout=self._timeout)
     json_data = json.loads(response.content.decode("utf8"))
     if json_data.get("items") != None:
         return PlacesResponse.new_from_jsondict(json_data)
     elif "error" in json_data:
         if json_data["error"] == "Unauthorized":
             raise UnauthorizedError(json_data["error_description"])
     else:
         raise HEREError(
             json_data.get(
                 "message",
                 "Error occurred on " + sys._getframe(1).f_code.co_name))
 def __get(self, data, path, json_node):
     url = Utils.build_url(self._base_url + path, extra_params=data)
     response = requests.get(url, timeout=self._timeout)
     json_data = json.loads(response.content.decode("utf8"))
     if json_node in json_data.get("Res", {}):
         return PublicTransitResponse.new_from_jsondict(json_data)
     elif "text" in json_data.get("Res", {}).get("Message", {}):
         raise HEREError(
             json_data["Res"]["Message"]["text"],
             "Error occurred on " + sys._getframe(1).f_code.co_name,
         )
     elif "error" in json_data:
         if json_data["error"] == "Unauthorized":
             raise UnauthorizedError(json_data["error_description"])
     else:
         raise HEREError("Error occurred on " +
                         sys._getframe(1).f_code.co_name)
Beispiel #4
0
 def __get(self, data):
     url = Utils.build_url(self._base_url, extra_params=data)
     response = requests.get(url, timeout=self._timeout)
     try:
         json_data = json.loads(response.content.decode("utf8"))
         if json_data.get("items") != None:
             return GeocoderReverseResponse.new_from_jsondict(json_data)
         elif "error" in json_data:
             if json_data["error"] == "Unauthorized":
                 raise UnauthorizedError(json_data["error_description"])
         else:
             raise HEREError(
                 json_data.get(
                     "Details",
                     "Error occurred on function " +
                     sys._getframe(1).f_code.co_name,
                 ))
     except ValueError as err:
         raise HEREError("Error occurred on function " +
                         sys._getframe(1).f_code.co_name + " " + str(err))