Python six.moves.http_client.responses() Examples

The following are 5 code examples of six.moves.http_client.responses(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module six.moves.http_client , or try the search function .
Example #1
Source File: cfn_custom_resource.py    From cfn-custom-resource with Mozilla Public License 2.0 6 votes vote down vote up
def send_response(cls, resource, url, response_content):
        if url == cls.DUMMY_RESPONSE_URL_SILENT:
            return
        elif url == cls.DUMMY_RESPONSE_URL_PRINT:
            six.print_(json.dumps(response_content, indent=2))
        else:
            put_response = requests.put(url,
                                        data=json.dumps(response_content))
            status_code = put_response.status_code
            response_text = put_response.text
            
            body_text = ""
            if status_code // 100 != 2:
                body_text = "\n" + response_text
            resource._base_logger.debug("Status code: {} {}{}".format(put_response.status_code, http_client.responses[put_response.status_code], body_text))

        return put_response 
Example #2
Source File: restclient.py    From manila with Apache License 2.0 6 votes vote down vote up
def __init__(self, logfunc=None, response=None, err=None):
        """Initialize a RestResult containing the results from a REST call.

        :param logfunc: debug log function.
        :param response: HTTP response.
        :param err: HTTP error.
        """
        self.response = response
        self.log_function = logfunc
        self.error = err
        self.data = ""
        self.status = 0
        if self.response:
            self.status = self.response.getcode()
            result = self.response.read()
            while result:
                self.data += result
                result = self.response.read()

        if self.error:
            self.status = self.error.code
            self.data = http_client.responses[self.status]

        log_debug_msg(self, 'Response code: %s' % self.status)
        log_debug_msg(self, 'Response data: %s' % self.data) 
Example #3
Source File: restclient.py    From manila with Apache License 2.0 5 votes vote down vote up
def __init__(self, status, name="ERR_INTERNAL", message=None):

        """Create a REST Response exception.

        :param status: HTTP response status.
        :param name: The name of the REST API error type.
        :param message: Descriptive error message returned from REST call.
        """
        super(RestClientError, self).__init__(message)
        self.code = status
        self.name = name
        self.msg = message
        if status in http_client.responses:
            self.msg = http_client.responses[status] 
Example #4
Source File: __init__.py    From realms-wiki with GNU General Public License v2.0 5 votes vote down vote up
def error_handler(e):
    try:
        if isinstance(e, HTTPException):
            status_code = e.code
            message = e.description if e.description != type(e).description else None
            tb = None
        else:
            status_code = httplib.INTERNAL_SERVER_ERROR
            message = None
            tb = traceback.format_exc() if current_user.admin else None

        if request.is_xhr or request.accept_mimetypes.best in ['application/json', 'text/javascript']:
            response = {
                'message': message,
                'traceback': tb
            }
        else:
            response = render_template('errors/error.html',
                                       title=httplib.responses[status_code],
                                       status_code=status_code,
                                       message=message,
                                       traceback=tb)
    except HTTPException as e2:
        return error_handler(e2)

    return response, status_code 
Example #5
Source File: http.py    From syntribos with Apache License 2.0 4 votes vote down vote up
def check_status_code(response):
    """Returns a signal with info about a response's HTTP status code

    :param response: A `Response` object
    :type response: :class:`requests.Response`
    :returns: Signal with status code details
    :rtype: :class:`syntribos.signal.SynSignal`
    """
    check_name = "HTTP_STATUS_CODE"
    codes = httplib.responses

    data = {
        "response": response,
        "status_code": response.status_code,
        "reason": response.reason,
    }
    if codes.get(response.status_code, None):
        data["details"] = codes[response.status_code]
    else:
        data["details"] = "Unknown"

    text = ("A {code} HTTP status code was returned by the server, with reason"
            " '{reason}'. This status code usually means '{details}'.").format(
                code=data["status_code"],
                reason=data["reason"],
                details=data["details"])

    slug = "HTTP_STATUS_CODE_{range}"
    tags = []

    if data["status_code"] in range(200, 300):
        slug = slug.format(range="2XX")

    elif data["status_code"] in range(300, 400):
        slug = slug.format(range="3XX")

        # CCNEILL: 304 == use local cache; not really a redirect
        if data["status_code"] != 304:
            tags.append("SERVER_REDIRECT")

    elif data["status_code"] in range(400, 500):
        slug = slug.format(range="4XX")
        tags.append("CLIENT_FAIL")

    elif data["status_code"] in range(500, 600):
        slug = slug.format(range="5XX")
        tags.append("SERVER_FAIL")

    slug = (slug + "_{code}").format(code=data["status_code"])

    return syntribos.signal.SynSignal(
        text=text,
        slug=slug,
        strength=1,
        tags=tags,
        data=data,
        check_name=check_name)