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


Python httplib.error方法代码示例

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


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

示例1: _fetch

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import error [as 别名]
def _fetch(self, url, payload=None, method=GET, headers={}, allow_truncated=False):
        if method in [POST, PUT]:
            payload = payload or ''
            if 'Content-Type' not in headers:
                headers['Content-Type'] = 'application/x-www-form-urlencoded'
        else:
            payload = ''
        for redirect_number in xrange(MAX_REDIRECTS+1):
            scheme, host, path, params, query, fragment = urlparse.urlparse(url)
            try:
                if scheme == 'http':
                    connection = httplib.HTTPConnection(host)
                elif scheme == 'https':
                    connection = httplib.HTTPSConnection(host)
                else:
                    raise InvalidURLError('Protocol \'%s\' is not supported.')

                if query != '':
                    full_path = path + '?' + query
                else:
                    full_path = path

                adjusted_headers = {
                    'Content-Length': len(payload),
                    'Host': host,
                    'Accept': '*/*',
                }
                for header in headers:
                    adjusted_headers[header] = headers[header]

                try:
                    connection.request(method, full_path, payload,
                                       adjusted_headers)
                    http_response = connection.getresponse()
                    http_response_data = http_response.read()
                finally:
                    connection.close()

                if http_response.status in REDIRECT_STATUSES:
                    newurl = http_response.getheader('Location', None)
                    if newurl is None:
                        raise DownloadError('Redirect is missing Location header.')
                    else:
                        url = urlparse.urljoin(url, newurl)
                        method = 'GET'
                else:
                    response = Response()
                    response.body = http_response_data
                    response.status_code = http_response.status
                    response.request = Request(full_path)
                    response.headers = {}
                    for header_key, header_value in http_response.getheaders():
                        response.headers[header_key] = header_value
                    return response

            except (httplib.error, socket.error, IOError), e:
                response = Response()
                response.request = Request(full_path)
                response.error = str(e) or 'unknown error'
                return response 
开发者ID:avelino,项目名称:bottle-auth,代码行数:62,代码来源:httpclient.py

示例2: search

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import error [as 别名]
def search(self, dork):
        """
        This method performs the effective search on Google providing
        the google dork and the Google session cookie
        """

        gpage = conf.googlePage if conf.googlePage > 1 else 1
        logger.info("using Google result page #%d" % gpage)

        if not dork:
            return None

        url = "https://www.google.com/search?"
        url += "q=%s&" % urlencode(dork, convall=True)
        url += "num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search"
        url += "&start=%d" % ((gpage - 1) * 100)

        try:
            conn = self.opener.open(url)

            requestMsg = "HTTP request:\nGET %s" % url
            requestMsg += " %s" % httplib.HTTPConnection._http_vsn_str
            logger.log(CUSTOM_LOGGING.TRAFFIC_OUT, requestMsg)

            page = conn.read()
            code = conn.code
            status = conn.msg
            responseHeaders = conn.info()
            page = decodePage(page, responseHeaders.get("Content-Encoding"), responseHeaders.get("Content-Type"))

            responseMsg = "HTTP response (%s - %d):\n" % (status, code)

            if conf.verbose <= 4:
                responseMsg += getUnicode(responseHeaders, UNICODE_ENCODING)
            elif conf.verbose > 4:
                responseMsg += "%s\n%s\n" % (responseHeaders, page)

            logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg)
        except urllib2.HTTPError, e:
            try:
                page = e.read()
            except Exception, ex:
                warnMsg = "problem occurred while trying to get "
                warnMsg += "an error page information (%s)" % getSafeExString(ex)
                logger.critical(warnMsg)
                return None 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:48,代码来源:google.py


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