Пример #1
0
    def get_response_object(self):
        with Session() as s:
            current_protocol = 'https://' if self.get_ssl_enabled() else 'http://'

            url = current_protocol + self.get_host() + self.get_url()

            if self.__port != 80:
                url = current_protocol + self.get_host() + ":" + str(self.__port) + self.get_url()

            req = Request(method=self.get_method(), url=url,
                          data=self.get_body(),
                          headers=self.get_headers(),
                          )
            prepped = s.prepare_request(req)

            proxy_https = os.environ.get('HTTPS_PROXY') or os.environ.get(
                'https_proxy')
            proxy_http = os.environ.get(
                'HTTP_PROXY') or os.environ.get('http_proxy')

            proxies = {
                "http": proxy_http,
                "https": proxy_https,
            }
            # ignore the warning-InsecureRequestWarning
            urllib3.disable_warnings()
            response = s.send(prepped, proxies=proxies,
                              timeout=(DEFAULT_CONNECT_TIMEOUT, self._timeout),
                              allow_redirects=False, verify=None, cert=None)
            return response.status_code, response.headers, response.content
    def get_response_object(self):
        with Session() as s:
            current_protocol = 'https://' if self.get_ssl_enabled(
            ) else 'http://'
            host = self.get_host()
            if host.startswith('https://') or\
                    not host.startswith('https://') and current_protocol == 'https://':
                port = ':%s' % self.__port if self.__port != 80 and self.__port != 443 else ''
            else:
                port = ':%s' % self.__port if self.__port != 80 else ''

            if host.startswith('http://') or host.startswith('https://'):
                url = host + port + self.get_url()
            else:
                url = current_protocol + host + port + self.get_url()

            req = Request(
                method=self.get_method(),
                url=url,
                data=self.get_body(),
                headers=self.get_headers(),
            )
            prepped = s.prepare_request(req)

            proxy_https = os.environ.get('HTTPS_PROXY') or os.environ.get(
                'https_proxy')
            proxy_http = os.environ.get('HTTP_PROXY') or os.environ.get(
                'http_proxy')

            proxies = {}
            if proxy_http:
                proxies['http'] = proxy_http
            if proxy_https:
                proxies['https'] = proxy_https

            response = s.send(prepped,
                              proxies=proxies,
                              timeout=(self.__connect_timeout,
                                       self.__read_timeout),
                              allow_redirects=False,
                              verify=self.get_verify_value(),
                              cert=None)

            http_debug = os.environ.get('DEBUG')

            if http_debug is not None and http_debug.lower() == 'sdk':
                # http debug information
                self.do_http_debug(prepped, response)

            return response.status_code, response.headers, response.content
    def get_response_object(self):
        with Session() as s:
            current_protocol = 'https://' if self.get_ssl_enabled(
            ) else 'http://'

            url = current_protocol + self.get_host() + self.get_url()

            if self.__port != 80:
                url = current_protocol + self.get_host() + ":" + str(
                    self.__port) + self.get_url()

            req = Request(
                method=self.get_method(),
                url=url,
                data=self.get_body(),
                headers=self.get_headers(),
            )
            prepped = s.prepare_request(req)

            proxy_https = os.environ.get('HTTPS_PROXY') or os.environ.get(
                'https_proxy')
            proxy_http = os.environ.get('HTTP_PROXY') or os.environ.get(
                'http_proxy')

            proxies = {
                "http": proxy_http,
                "https": proxy_https,
            }

            response = s.send(prepped,
                              proxies=proxies,
                              timeout=(self.__connect_timeout,
                                       self.__read_timeout),
                              allow_redirects=False,
                              verify=self.get_verify_value(),
                              cert=None)

            http_debug = os.environ.get('DEBUG')

            if http_debug is not None and http_debug.lower() == 'sdk':
                # http debug information
                self.do_http_debug(prepped, response)

            return response.status_code, response.headers, response.content