예제 #1
0
    def _url_query(self, api_call, retries=0):
        try:
            if self.debug:
                print("Query url: " + self.url + api_call)
            response = urllib.request.urlopen(self.url + api_call)
            if response.code == 200:
                return True
            return False  # pragma: no cover

        except urllib.error.HTTPError as e:
            if e.code == 409:
                raise exceptions.AddressAlreadyRegistered(self.address,
                                                          self.url)
            elif e.code == 404:
                raise exceptions.FarmerNotFound(self.url)
            elif e.code == 400:
                raise exceptions.InvalidAddress(self.address)
            elif e.code == 500:  # pragma: no cover
                raise exceptions.FarmerError(self.url)  # pragma: no cover
            else:
                raise e  # pragma: no cover
        except urllib.error.URLError:
            if retries >= self.connection_retry_limit:
                raise exceptions.ConnectionError(self.url)
            time.sleep(self.connection_retry_delay)
            return self._url_query(api_call, retries + 1)
예제 #2
0
    def _url_query(self, api_call, retries=0):
        try:
            if self.debug:
                print("Query url: " + self.url + api_call)
            response = urllib.request.urlopen(self.url + api_call)
            if response.code == 200:
                return True
            return False  # pragma: no cover

        except urllib.error.HTTPError as e:
            if e.code == 409:
                raise exceptions.AddressAlreadyRegistered(
                    self.address, self.url)
            elif e.code == 404:
                raise exceptions.FarmerNotFound(self.url)
            elif e.code == 400:
                raise exceptions.InvalidAddress(self.address)
            elif e.code == 500:  # pragma: no cover
                raise exceptions.FarmerError(self.url)  # pragma: no cover
            else:
                raise e  # pragma: no cover
        except HTTPException:
            self._handle_connection_error(api_call, retries)
        except urllib.error.URLError:
            self._handle_connection_error(api_call, retries)
        except socket.error:
            self._handle_connection_error(api_call, retries)
예제 #3
0
 def _url_query(self, api_path, retries=0, authenticate=True):
     try:
         req = urllib.request.Request(self._server_url + api_path)
         if self._get_wif() and authenticate:
             headers = self._create_authentication_headers()
             req.add_header("Date", headers["Date"])
             req.add_header("Authorization", headers["Authorization"])
         response = urllib.request.urlopen(req)
         if response.code == 200:
             return response.read()
     except urllib.error.HTTPError as e:
         if e.code == 409:
             raise exceptions.AddressAlreadyRegistered(
                 self.auth_address(), self._server_url)
         elif e.code == 404:
             raise exceptions.FarmerNotFound(self._server_url)
         elif e.code == 400:
             raise exceptions.InvalidAddress(self.auth_address())
         elif e.code == 500:  # pragma: no cover
             raise exceptions.FarmerError(self._server_url)
         else:
             raise e  # pragma: no cover
     except http.client.HTTPException:
         self._handle_connection_error(api_path, retries, authenticate)
     except urllib.error.URLError:
         self._handle_connection_error(api_path, retries, authenticate)
     except socket.error:
         self._handle_connection_error(api_path, retries, authenticate)