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


Python error.Error方法代码示例

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


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

示例1: handleResponse

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def handleResponse(self, response):
        if self.quietLoss:
            return
        if self.failed:
            self.factory.noPage(
                Failure(
                    error.Error(
                        self.status, self.message, response)))
        if self.factory.method == b'HEAD':
            # Callback with empty string, since there is never a response
            # body for HEAD requests.
            self.factory.page(b'')
        elif self.length != None and self.length != 0:
            self.factory.noPage(Failure(
                PartialDownloadError(self.status, self.message, response)))
        else:
            self.factory.page(response)
        # server might be stupid and not close connection. admittedly
        # the fact we do only one request per connection is also
        # stupid...
        self.transport.loseConnection() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:client.py

示例2: _http_do

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def _http_do(url, headers, timeout, method, params):
    id_ = 0
    
    try:
        data = yield client.getPage(
            url=url,
            method='POST',
            headers=dict(headers, **{'Content-Type': 'application/json'}),
            postdata=json.dumps({
                'jsonrpc': '2.0',
                'method': method,
                'params': params,
                'id': id_,
            }),
            timeout=timeout,
        )
    except error.Error, e:
        try:
            resp = json.loads(e.response)
        except:
            raise e 
开发者ID:donSchoe,项目名称:p2pool-n,代码行数:23,代码来源:jsonrpc.py

示例3: handleResponse

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def handleResponse(self, response):
        if self.quietLoss:
            return
        if self.failed:
            self.factory.noPage(
                failure.Failure(
                    error.Error(
                        self.status, self.message, response)))
        if self.factory.method == 'HEAD':
            # Callback with empty string, since there is never a response
            # body for HEAD requests.
            self.factory.page('')
        elif self.length != None and self.length != 0:
            self.factory.noPage(failure.Failure(
                PartialDownloadError(self.status, self.message, response)))
        else:
            self.factory.page(response)
        # server might be stupid and not close connection. admittedly
        # the fact we do only one request per connection is also
        # stupid...
        self.transport.loseConnection() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:client.py

示例4: handleResponse

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def handleResponse(self, response):
        if self.quietLoss:
            return
        if self.failed:
            self.factory.noPage(
                failure.Failure(
                    error.Error(
                        self.status, self.message, response)))
        elif self.length != None and self.length != 0:
            self.factory.noPage(failure.Failure(
                PartialDownloadError(self.status, self.message, response)))
        else:
            self.factory.page(response)
        # server might be stupid and not close connection. admittedly
        # the fact we do only one request per connection is also
        # stupid...
        self.transport.loseConnection() 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:19,代码来源:client.py

示例5: handleFailure

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import 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

示例6: error_response

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def error_response(bucket, error_message='', code=http.BAD_REQUEST, with_traceback=False):
        """
        Error handling method logging and returning appropriate stacktrace.
        """
        # FIXME: Check for privacy. Do something more sane with the stacktrace
        #        or enable only when sending appropriate request arguments.
        if with_traceback:
            error_message += '\n' + last_error_and_traceback()
            log.error(error_message)
        bucket.request.setResponseCode(code)
        #bucket.request.setHeader('Content-Type', 'text/plain; charset=utf-8')
        return error_message.encode('utf-8') 
开发者ID:daq-tools,项目名称:kotori,代码行数:14,代码来源:http.py

示例7: handleResponseEnd

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def handleResponseEnd(self):
        if self.length:
            self.transmittingPage = 0
            self.factory.noPage(
                Failure(
                    PartialDownloadError(self.status)))
        if self.transmittingPage:
            self.factory.pageEnd()
            self.transmittingPage = 0
        if self.failed:
            self.factory.noPage(
                Failure(
                    error.Error(
                        self.status, self.message, None)))
            self.transport.loseConnection() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:client.py

示例8: noPage

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def noPage(self, reason):
        """
        Close the storage file and errback the waiting L{Deferred} with the
        given reason.
        """
        if self.waiting:
            self.waiting = 0
            if self.file:
                try:
                    self.file.close()
                except:
                    log.err(None, "Error closing HTTPDownloader file")
            self.deferred.errback(reason) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:client.py

示例9: test_noMessageValidStatus

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def test_noMessageValidStatus(self):
        """
        If no C{message} argument is passed to the L{Error} constructor and the
        C{code} argument is a valid HTTP status code, C{code} is mapped to a
        descriptive string to which C{message} is assigned.
        """
        e = error.Error(b"200")
        self.assertEqual(e.message, b"OK") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_error.py

示例10: test_noMessageInvalidStatus

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def test_noMessageInvalidStatus(self):
        """
        If no C{message} argument is passed to the L{Error} constructor and
        C{code} isn't a valid HTTP status code, C{message} stays L{None}.
        """
        e = error.Error(b"InvalidCode")
        self.assertEqual(e.message, None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_error.py

示例11: test_str

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def test_str(self):
        """
        C{str()} on an L{Error} returns the code and message it was
        instantiated with.
        """
        # Bytestring status
        e = error.Error(b"200", b"OK")
        self.assertEqual(str(e), "200 OK")

        # int status
        e = error.Error(200, b"OK")
        self.assertEqual(str(e), "200 OK") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_error.py

示例12: _downloadTest

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def _downloadTest(self, method):
        dl = []
        for (url, code) in [("nosuchfile", b"404"), ("error", b"401"),
                            ("error?showlength=1", b"401")]:
            d = method(url)
            d = self.assertFailure(d, error.Error)
            d.addCallback(lambda exc, code=code: self.assertEqual(exc.args[0], code))
            dl.append(d)
        return defer.DeferredList(dl, fireOnOneErrback=True) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_webclient.py

示例13: testMethodNotFound

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def testMethodNotFound(self):
        """
        Check that a non existing method return error 500.
        """
        d = self.proxy().callRemote('doesntexist')
        self.assertFailure(d, error.Error)
        def cb(err):
            self.assertEqual(int(err.status), 500)
        d.addCallback(cb)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_soap.py

示例14: noPage

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def noPage(self, reason):
        """
        Close the storage file and errback the waiting L{Deferred} with the
        given reason.
        """
        if self.waiting:
            self.waiting = 0
            if self.file:
                try:
                    self.file.close()
                except:
                    self._log.failure("Error closing HTTPDownloader file")
            self.deferred.errback(reason) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:15,代码来源:client.py

示例15: checkHTTPError

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import Error [as 别名]
def checkHTTPError(failure, url):
    failure.trap(weberror.Error)

    if failure.value.status=='401':
        print('>>>', sys.stderr, failure.getErrorMessage())

        username = input('用户名:')
        password = getpass.getpass('密码:')
        basicAuth = base64.encodestring('%s:%s' % (username, password))
        authHeader = 'Basic' + basicAuth.strip()
        # 加入验证信息后,尝试再次获取页面,
        return client.getPage(url.encode(), headers={'Authorization':authHeader})
    else:
        return failure 
开发者ID:ScrappyZhang,项目名称:python_web_Crawler_DA_ML_DL,代码行数:16,代码来源:t10webchat_password.py


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