当前位置: 首页>>代码示例>>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;未经允许,请勿转载。