當前位置: 首頁>>代碼示例>>Python>>正文


Python Dependency.make_post_request方法代碼示例

本文整理匯總了Python中common.utilities.inversion_of_control.Dependency.make_post_request方法的典型用法代碼示例。如果您正苦於以下問題:Python Dependency.make_post_request方法的具體用法?Python Dependency.make_post_request怎麽用?Python Dependency.make_post_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common.utilities.inversion_of_control.Dependency的用法示例。


在下文中一共展示了Dependency.make_post_request方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ArcGISConnection

# 需要導入模塊: from common.utilities.inversion_of_control import Dependency [as 別名]
# 或者: from common.utilities.inversion_of_control.Dependency import make_post_request [as 別名]
class ArcGISConnection(object):
    """
    This class is in charge of keeping track of an ArcGIS server and making calls to it
    """

    def __init__(self, server_ip_address):
        self._rest_provider = Dependency("RestProvider", HasMethods("download_file")).value
        self._config = Dependency("Config", HasAttributes("ArcGIS_timeout", "ArcGIS_max_errors")).value
        self._logger = Dependency("LogManager", HasMethods("error")).value
        self._server_ip_address = server_ip_address
        self._timeout = self._config.ArcGIS_timeout
        self._max_error_count = self._config.ArcGIS_max_errors

    def download_file(self, url):

        try:

            # append the server ip to the url
            url = self._append_ip_address_to_url(url)

            # download the file
            return self._rest_provider.download_file(url)

        except Exception as ex:

            # this has been timing out a lot, so I'm adding some logging...
            self._logger.critical("Exception on ESRI Server: " % str(self._server_ip_address))
            self._logger.critical(str(ex))
            self._logger.critical(traceback.format_exc())
            raise

    def generate_report(self, request_format, url):
        # append the server ip to the url
        url = self._append_ip_address_to_url(url)

        # the ArcGIS server has weird errors. This ensures that we loop several times until a good response is returned
        successful_response = False
        request_counter = 0
        response = None

        while not successful_response:

            # try to get the request and handle errors properly (so that we can retry)
            try:
                response = self._rest_provider.make_post_request(url, request_format, time_out = self._timeout)

            except Exception as e:
                # if there's an error, log it and try again
                response = None
                error_text = str(e)
                self._logger.critical("error send ArcGIS report (exception): %s" + str(error_text))

                # if it's a timeout, register the server ip address, so that it keeps count
                # treat token required as a time out, so that those servers are taken out of the pool
                if "Request timed out" in error_text or "timeout" in error_text or "Token Required" in error_text:
                    ArcGISConnectionManager.instance.register_timeout(self._server_ip_address)

            # once we get a response back, check it's type
            if response is not None:

                # this signals a successful response
                gp19_success_response_text = '{"paramName":"OutputStatus","dataType":"GPBoolean","value":true}'
                if response.text.find('arcgisoutput') != -1 or response.text.find('stops') != -1 \
                    or response.text.find("rings") != -1 or response.text.find(gp19_success_response_text) != -1:

                    # mark for exit and reset the timeout count
                    successful_response = True
                    ArcGISConnectionManager.instance.reset_timeout_count_on_successful_connection(self._server_ip_address)

                # if it's a timeout, register the server ip address
                # treat token required as a time out, so that those servers are taken out of the pool
                elif "Request timed out" in response.text or "timeout" in response.text or "Token Required" in response.text:
                    ArcGISConnectionManager.instance.register_timeout(self._server_ip_address)
                elif 'No solution found.' in response.text and 'useHierarchy' in request_format and request_format['useHierarchy'] == 'true':
                    request_format['useHierarchy'] = 'false'
                else:
                    self._logger.critical("error send ArcGIS report (no arcgisoutput): %s" + response.text)

            else:
                self._logger.critical("error send ArcGIS report (response is None)")

            if request_counter >= self._max_error_count:
                raise Exception('too many requests - %s' % url)

            # increment the request counter
            request_counter += 1

        return response

    def _append_ip_address_to_url(self, url):
        if url is not None and url[:4] != 'http':
            url = ''.join(['http://', self._server_ip_address, '/arcgis', url])
        return url
開發者ID:erezrubinstein,項目名稱:aa,代碼行數:95,代碼來源:ArcGIS_connection_manager.py


注:本文中的common.utilities.inversion_of_control.Dependency.make_post_request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。