当前位置: 首页>>代码示例>>Python>>正文


Python http.INTERNAL_SERVER_ERROR属性代码示例

本文整理汇总了Python中twisted.web.http.INTERNAL_SERVER_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Python http.INTERNAL_SERVER_ERROR属性的具体用法?Python http.INTERNAL_SERVER_ERROR怎么用?Python http.INTERNAL_SERVER_ERROR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在twisted.web.http的用法示例。


在下文中一共展示了http.INTERNAL_SERVER_ERROR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: processingFailed

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def processingFailed(self, reason):
        log.err(reason)
        if self.site.displayTracebacks:
            body = (b"<html><head><title>web.Server Traceback"
                    b" (most recent call last)</title></head>"
                    b"<body><b>web.Server Traceback"
                    b" (most recent call last):</b>\n\n" +
                    util.formatFailure(reason) +
                    b"\n\n</body></html>\n")
        else:
            body = (b"<html><head><title>Processing Failed"
                    b"</title></head><body>"
                    b"<b>Processing Failed</b></body></html>")

        self.setResponseCode(http.INTERNAL_SERVER_ERROR)
        self.setHeader(b'content-type', b"text/html")
        self.setHeader(b'content-length', intToBytes(len(body)))
        self.write(body)
        self.finish()
        return reason 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:server.py

示例2: processEnded

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def processEnded(self, reason):
        if reason.value.exitCode != 0:
            self._log.error("CGI {uri} exited with exit code {exitCode}",
                    uri=self.request.uri, exitCode=reason.value.exitCode)
        if self.errortext:
            self._log.error("Errors from CGI {uri}: {errorText}",
                uri=self.request.uri, errorText=self.errortext)
        if self.handling_headers:
            self._log.error("Premature end of headers in {uri}: {headerText}",
                uri=self.request.uri, headerText=self.headertext)
            self.request.write(
                resource.ErrorPage(http.INTERNAL_SERVER_ERROR,
                    "CGI Script Error",
                    "Premature end of script headers.").render(self.request))
        self.request.unregisterProducer()
        self.request.finish() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:18,代码来源:twcgi.py

示例3: processingFailed

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def processingFailed(self, reason):
        log.err(reason)
        if self.site.displayTracebacks:
            body = ("<html><head><title>web.Server Traceback (most recent call last)</title></head>"
                    "<body><b>web.Server Traceback (most recent call last):</b>\n\n"
                    "%s\n\n</body></html>\n"
                    % webutil.formatFailure(reason))
        else:
            body = ("<html><head><title>Processing Failed</title></head><body>"
                  "<b>Processing Failed</b></body></html>")

        self.setResponseCode(http.INTERNAL_SERVER_ERROR)
        self.setHeader('content-type',"text/html")
        self.setHeader('content-length', str(len(body)))
        self.write(body)
        self.finish()
        return reason 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,代码来源:server.py

示例4: render_POST

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def render_POST(self, request):
        account_recovery = AccountRecovery(
            self._authenticator.bonafide_session,
            self.soledad(request),
            self._service(request, '_leap_session').smtp_config,
            self._get_backup_email(request),
            self._leap_provider.server_name,
            language=self._get_language(request))

        def update_response(response):
            request.setResponseCode(NO_CONTENT)
            request.finish()

        def error_response(response):
            request.setResponseCode(INTERNAL_SERVER_ERROR)
            request.finish()

        d = account_recovery.update_recovery_code()
        d.addCallbacks(update_response, error_response)
        return NOT_DONE_YET 
开发者ID:pixelated,项目名称:pixelated-user-agent,代码行数:22,代码来源:backup_account_resource.py

示例5: delayed

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def delayed(f):
    def decorator(resource, request):
        @defer.inlineCallbacks
        def wrapper():
            try:
                yield f(resource, request)
            except Exception as e:
                log.error("Error in delayed decorator wrapped function: {e}", e=e)
                request.setResponseCode(http.INTERNAL_SERVER_ERROR)
                request.finish()
        wrapper()
        return server.NOT_DONE_YET
    return decorator 
开发者ID:moira-alert,项目名称:worker,代码行数:15,代码来源:request.py

示例6: handleFailure

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def handleFailure(f, request=None):
    """
    Handle failure in callback chain, log and respond with traceback.

    See also:
    https://twistedmatrix.com/documents/16.0.0/core/howto/defer.html#errbacks
    """
    if f.type is Error:
        if request:
            request.setResponseCode(int(f.value.status))

        if hasattr(f.value, 'with_traceback'):
            f.with_traceback = f.value.with_traceback

        msg = None
        if isinstance(f.value.response, Failure):
            msg = f.value.response.getErrorMessage()
        elif type(f.value.response) in types.StringTypes:
            msg = f.value.response
        request.messages.append({'type': 'error', 'message': msg})

    else:
        if request:
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            request.setHeader('Content-Type', 'text/plain; charset=utf-8')
        f.with_traceback = True

    if hasattr(f, 'with_traceback') and f.with_traceback:

        traceback = f.getTraceback()
        log.error(traceback)
        #f.trap(RuntimeError)
        request.write(traceback.encode('utf-8')) 
开发者ID:daq-tools,项目名称:kotori,代码行数:35,代码来源:util.py

示例7: run

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def run(self):
        """
        Call the WSGI application object, iterate it, and handle its output.

        This must be called in a non-I/O thread (ie, a WSGI application
        thread).
        """
        try:
            appIterator = self.application(self.environ, self.startResponse)
            for elem in appIterator:
                if elem:
                    self.write(elem)
                if self._requestFinished:
                    break
            close = getattr(appIterator, 'close', None)
            if close is not None:
                close()
        except:
            def wsgiError(started, type, value, traceback):
                err(Failure(value, type, traceback), "WSGI application error")
                if started:
                    self.request.loseConnection()
                else:
                    self.request.setResponseCode(INTERNAL_SERVER_ERROR)
                    self.request.finish()
            self.reactor.callFromThread(wsgiError, self.started, *exc_info())
        else:
            def wsgiFinish(started):
                if not self._requestFinished:
                    if not started:
                        self._sendResponseHeaders()
                    self.request.finish()
            self.reactor.callFromThread(wsgiFinish, self.started)
        self.started = True 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:36,代码来源:wsgi.py

示例8: failed

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def failed(self, failure):
        #XXX: Argh. FIXME.
        failure = str(failure)
        self.request.write(
            resource.ErrorPage(http.INTERNAL_SERVER_ERROR,
                               "Server Connection Lost",
                               "Connection to distributed server lost:" +
                               util._PRE(failure)).
            render(self.request))
        self.request.finish()
        log.msg(failure) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:distrib.py

示例9: processEnded

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def processEnded(self, reason):
        if reason.value.exitCode != 0:
            log.msg("CGI %s exited with exit code %s" %
                    (self.request.uri, reason.value.exitCode))
        if self.errortext:
            log.msg("Errors from CGI %s: %s" % (self.request.uri, self.errortext))
        if self.handling_headers:
            log.msg("Premature end of headers in %s: %s" % (self.request.uri, self.headertext))
            self.request.write(
                resource.ErrorPage(http.INTERNAL_SERVER_ERROR,
                                   "CGI Script Error",
                                   "Premature end of script headers.").render(self.request))
        self.request.unregisterProducer()
        self.request.finish() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:twcgi.py

示例10: test_prematureEndOfHeaders

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def test_prematureEndOfHeaders(self):
        """
        If the process communicating with L{CGIProcessProtocol} ends before
        finishing writing out headers, the response has I{INTERNAL SERVER
        ERROR} as its status code.
        """
        request = DummyRequest([''])
        protocol = twcgi.CGIProcessProtocol(request)
        protocol.processEnded(failure.Failure(error.ProcessTerminated()))
        self.assertEqual(request.responseCode, INTERNAL_SERVER_ERROR) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_cgi.py

示例11: test_novaclient_exception

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def test_novaclient_exception(self, logger):
        """
        The details of ``novaclient.exceptions.ClientException`` are logged
        when it is raised by the decorated method and the exception is still
        raised.
        """
        result = NovaClientException(
            code=INTERNAL_SERVER_ERROR,
            message="Some things went wrong with some other things.",
            details={"key": "value"},
            request_id="abcdefghijklmnopqrstuvwxyz",
            url="/foo/bar",
            method="POST",
        )
        logging_dummy = LoggingDummy(Dummy(result))
        self.assertRaises(NovaClientException, logging_dummy.raise_method)

        logged = LoggedMessage.of_type(
            logger.messages, NOVA_CLIENT_EXCEPTION,
        )[0]
        assertContainsFields(
            self, logged.message, {
                u"code": result.code,
                u"message": result.message,
                u"details": result.details,
                u"request_id": result.request_id,
                u"url": result.url,
                u"method": result.method,
            },
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:32,代码来源:test_openstack.py

示例12: test_keystone_client_exception

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def test_keystone_client_exception(self, logger):
        """
        ``keystoneclient.openstack.common.apiclient.exceptions.BadRequest`` is
        treated similarly to ``novaclient.exceptions.ClientException``.

        See ``test_novaclient_exception``.
        """
        response = Response()
        response._content = "hello world"
        result = KeystoneHttpError(
            message="Some things went wrong with some other things.",
            details={"key": "value"},
            response=response,
            request_id="abcdefghijklmnopqrstuvwxyz",
            url="/foo/bar",
            method="POST",
            http_status=INTERNAL_SERVER_ERROR,
        )
        logging_dummy = LoggingDummy(Dummy(result))
        self.assertRaises(KeystoneHttpError, logging_dummy.raise_method)

        logged = LoggedMessage.of_type(
            logger.messages, KEYSTONE_HTTP_ERROR,
        )[0]
        assertContainsFields(
            self, logged.message, {
                u"code": result.http_status,
                u"message": result.message,
                u"details": result.details,
                u"request_id": result.request_id,
                u"url": result.url,
                u"method": result.method,
                u"response": "hello world",
            },
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:37,代码来源:test_openstack.py

示例13: _is_known_retryable

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def _is_known_retryable(exception):
    """
    Determine if the text of a Docker 500 error represents a case which
    warrants an automatic retry.

    :param Exception exception: The exception from a ``docker.Client`` method
        call.

    :return bool: ``True`` if the exception represents a failure that is likely
        transient and a retry makes sense, ``False`` otherwise.
    """
    # A problem coming out of Docker itself
    if isinstance(exception, APIError):
        if exception.response.status_code == INTERNAL_SERVER_ERROR:
            error_text = exception.response.text
            return any(
                known in error_text
                for known
                in [
                    # https://github.com/docker/docker/issues/18194
                    u"Unknown device",
                    # https://github.com/docker/docker/issues/17653
                    u"no such device",
                ]
            )

    # A connection problem coming from the requests library used by docker-py
    if isinstance(exception, ConnectionError):
        if (
            len(exception.args) > 0 and
            isinstance(exception.args[0], ProtocolError)
        ):
            if (
                len(exception.args[0].args) > 1 and
                isinstance(exception.args[0].args[1], socket_error)
            ):
                return exception.args[0].args[1].errno in {ECONNREFUSED}

    return False 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:41,代码来源:_docker.py

示例14: _stop_container

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def _stop_container(self, container_name):
        """Attempt to stop the given container.

        There is a race condition between a process dying and
        Docker noticing that fact:

        https://github.com/docker/docker/issues/5165#issuecomment-65753753

        If we get an error indicating that this race condition happened,
        return False. This means the caller should try again. If we *do*
        successfully stop the container, return True.

        :raise APIError: If the container failed to stop for some unknown
            reason.
        :return: True if we stopped the container, False otherwise.

        """
        try:
            with start_action(
                action_type='flocker:docker:container_stop',
                container=container_name
            ):
                self._client.stop(container_name)
        except APIError as e:
            if e.response.status_code == NOT_FOUND:
                # If the container doesn't exist, we swallow the error,
                # since this method is supposed to be idempotent.
                return True
            elif e.response.status_code == INTERNAL_SERVER_ERROR:
                # Docker returns this if the process had died, but
                # hasn't noticed it yet.
                return False
            else:
                raise
        return True 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:37,代码来源:_docker.py

示例15: _remove_container

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import INTERNAL_SERVER_ERROR [as 别名]
def _remove_container(self, container_name):
        """
        Attempt to remove a container.

        Assumes the given container has already been stopped.

        :param unicode container_name: The fully-namespaced name of the
            container.
        :return: True if we removed the container, False otherwise.
        """
        try:
            # The ``docker.Client.stop`` method sometimes returns a
            # 404 error, even though the container exists.
            # See https://github.com/docker/docker/issues/13088
            # Wait until the container has actually stopped running
            # before attempting to remove it.  Otherwise we are
            # likely to see: 'docker.errors.APIError: 409 Client
            # Error: Conflict ("Conflict, You cannot remove a
            # running container. Stop the container before
            # attempting removal or use -f")'
            # This code should probably be removed once the above
            # issue has been resolved. See [FLOC-1850]
            self._client.wait(container_name)

            with start_action(
                action_type='flocker:docker:container_remove',
                container=container_name
            ):
                self._client.remove_container(container_name)
        except APIError as e:
            if e.response.status_code == NOT_FOUND:
                # If the container doesn't exist, we swallow the error,
                # since this method is supposed to be idempotent.
                return True
            elif e.response.status_code == INTERNAL_SERVER_ERROR:
                # Failure to remove container - see FLOC-3262 for an example.
                return False
            else:
                raise
        return True 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:42,代码来源:_docker.py


注:本文中的twisted.web.http.INTERNAL_SERVER_ERROR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。