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


Python error.HTTPError方法代码示例

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


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

示例1: _http_request

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def _http_request(url, headers=None, time_out=10):
    """Perform an HTTP request and return request"""
    log(0, 'Request URL: {url}', url=url)

    try:
        if headers:
            request = Request(url, headers=headers)
        else:
            request = Request(url)
        req = urlopen(request, timeout=time_out)
        log(0, 'Response code: {code}', code=req.getcode())
        if 400 <= req.getcode() < 600:
            raise HTTPError('HTTP %s Error for url: %s' % (req.getcode(), url), response=req)
    except (HTTPError, URLError) as err:
        log(2, 'Download failed with error {}'.format(err))
        if yesno_dialog(localize(30004), '{line1}\n{line2}'.format(line1=localize(30063), line2=localize(30065))):  # Internet down, try again?
            return _http_request(url, headers, time_out)
        return None

    return req 
开发者ID:emilsvennesson,项目名称:script.module.inputstreamhelper,代码行数:22,代码来源:utils.py

示例2: HTML

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def HTML(self, check):
        try:
            if self.UserAgent != None:
                page_html = urlopen(Request(
                        self.target_url,
                        headers={"User-Agent":self.UserAgent}),
                        timeout=self.TimeOut).read().decode("utf-8")

            #If not, the default will be used
            else:
                page_html = urlopen(
                        self.target_url,
                        timeout=self.TimeOut).read().decode("utf-8")

        except HTTPError:
            page_html = "Can't get page source code"

        if self.verbose == True:
            print(" [+] Source code got from %s" % self.target_url)
            print("----START" + "-"*71)
            print(page_html)
            print("----END" + "-"*73)

        return(page_html) 
开发者ID:fnk0c,项目名称:dot2moon,代码行数:26,代码来源:connection.py

示例3: _make_request

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def _make_request(self, opener, request, timeout=None):
        """Make the API call and return the response. This is separated into
           it's own function, so we can mock it easily for testing.

        :param opener:
        :type opener:
        :param request: url payload to request
        :type request: urllib.Request object
        :param timeout: timeout value or None
        :type timeout: float
        :return: urllib response
        """
        timeout = timeout or self.timeout
        try:
            return opener.open(request, timeout=timeout)
        except HTTPError as err:
            exc = handle_error(err)
            return exc 
开发者ID:d6t,项目名称:d6tpipe,代码行数:20,代码来源:client.py

示例4: find_cf_issues

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def find_cf_issues(domains):

    error_domains = []

    for domain in domains:
        try:
            response = urlopen('http://' + domain)
        except HTTPError as e:
            if e.code == 403 and 'Bad request' in e.fp.read():
                try:
                    response = urlopen('https://' + domain)
                except URLError as e:
                    if 'handshake' in str(e).lower() or e.code == 403 and 'Bad request' in e.fp.read():
                        error_domains.append(domain)
                except:
                    pass
        except:
            pass

    return error_domains

# add a domain to CloudFront 
开发者ID:MindPointGroup,项目名称:cloudfrunt,代码行数:24,代码来源:cloudfrunt.py

示例5: login

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def login(server, username, password, alias) -> None:
    data = {
        "username": username,
        "password": password,
    }
    try:
        with urlopen(f"{server}/_matrix/maubot/v1/auth/login",
                     data=json.dumps(data).encode("utf-8")) as resp_data:
            resp = json.load(resp_data)
            config["servers"][server] = resp["token"]
            if not config["default_server"]:
                print(Fore.CYAN, "Setting", server, "as the default server")
                config["default_server"] = server
            if alias:
                config["aliases"][alias] = server
            save_config()
            print(Fore.GREEN + "Logged in successfully")
    except HTTPError as e:
        try:
            err = json.load(e)
        except json.JSONDecodeError:
            err = {}
        print(Fore.RED + err.get("error", str(e)) + Fore.RESET) 
开发者ID:maubot,项目名称:maubot,代码行数:25,代码来源:login.py

示例6: binaries_of_product

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def binaries_of_product(self, project, product, repo=None, arch=None):
        if repo is None:
            repo = self.project.product_repo
        if arch is None:
            arch = self.project.product_arch

        url = self.api.makeurl(['build', project, repo, arch, product])
        try:
            f = self.api.retried_GET(url)
        except HTTPError:
            return []

        ret = []
        root = ET.parse(f).getroot()
        for binary in root.findall('binary'):
            ret.append(binary.get('filename'))

        return ret 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:20,代码来源:manager.py

示例7: _retried_request

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def _retried_request(self, url, func, data=None):
        retry_sleep_seconds = 1
        while True:
            try:
                if data is not None:
                    return func(url, data=data)
                return func(url)
            except HTTPError as e:
                if 500 <= e.code <= 599:
                    print('Error {}, retrying {} in {}s'.format(e.code, url, retry_sleep_seconds))
                elif e.code == 400 and e.reason == 'service in progress':
                    print('Service in progress, retrying {} in {}s'.format(url, retry_sleep_seconds))
                else:
                    raise e
                time.sleep(retry_sleep_seconds)
                # increase sleep time up to one minute to avoid hammering
                # the server in case of real problems
                if (retry_sleep_seconds % 60):
                    retry_sleep_seconds += 1 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:21,代码来源:stagingapi.py

示例8: package_source_hash

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def package_source_hash(apiurl, project, package, revision=None):
    query = {}
    if revision:
        query['rev'] = revision

    # Will not catch packages that previous had a link, but no longer do.
    if package_source_link_copy(apiurl, project, package):
        query['expand'] = 1

    try:
        url = makeurl(apiurl, ['source', project, package], query)
        root = ETL.parse(http_GET(url)).getroot()
    except HTTPError as e:
        if e.code == 400 or e.code == 404:
            # 400: revision not found, 404: package not found.
            return None

        raise e

    if revision and root.find('error') is not None:
        # OBS returns XML error instead of HTTP 404 if revision not found.
        return None

    from osclib.util import sha1_short
    return sha1_short(root.xpath('entry[@name!="_link"]/@md5')) 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:27,代码来源:core.py

示例9: load_request

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def load_request(self, request_id):
        if not _is_int(request_id):
            return None

        url = makeurl(self.api.apiurl, ['request', str(request_id)])
        try:
            f = http_GET(url)
        except HTTPError:
            return None

        root = ET.parse(f).getroot()

        if root.get('id', None) != str(request_id):
            return None

        return root 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:18,代码来源:request_finder.py

示例10: check_image_bdeps

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def check_image_bdeps(self, project, arch):
        for dvd in ('000product:openSUSE-dvd5-dvd-{}'.format(arch), 'Test-DVD-{}'.format(arch)):
            try:
                url = makeurl(self.api.apiurl, ['build', project, 'images', arch, dvd, '_buildinfo'])
                root = ET.parse(http_GET(url)).getroot()
            except HTTPError as e:
                if e.code == 404:
                    continue
                raise
            for bdep in root.findall('bdep'):
                if 'name' not in bdep.attrib:
                    continue
                b = bdep.attrib['name']
                if b not in self.bin2src:
                    print("{} not found in bin2src".format(b))
                    continue
                b = self.bin2src[b]
                self.pkgdeps[b] = 'MYdvd{}'.format(self.api.rings.index(project))
            break 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:21,代码来源:cleanup_rings.py

示例11: get_dstrepos

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def get_dstrepos(self, project):
        url = osc.core.makeurl(self.apiurl, ('source', project, '_meta'))
        try:
            root = ET.parse(osc.core.http_GET(url)).getroot()
        except HTTPError:
            return None

        repos = set()
        for repo in root.findall('repository'):
            name = repo.attrib['name']
            if project in REPO_WHITELIST and name not in REPO_WHITELIST[project]:
                continue

            for node in repo.findall('arch'):
                arch = node.text

                if project in ARCH_WHITELIST and arch not in ARCH_WHITELIST[project]:
                    continue

                if project in ARCH_BLACKLIST and arch in ARCH_BLACKLIST[project]:
                    continue

                repos.add((name, arch))

        return repos 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:27,代码来源:abichecker.py

示例12: has_whitelist_warnings

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def has_whitelist_warnings( self, source_project, source_package, target_project, target_package ):
        # this checks if this is a submit to an product project and it has warnings for non-whitelisted permissions/files
        found_entries = set()
        url = osc.core.makeurl(self.apiurl, ['build', target_project])
        xml = ET.parse(osc.core.http_GET(url)).getroot()
        for f in xml.findall('entry'):
            # we check all repos in the source project for errors that exist in the target project
            repo = f.attrib['name']
            query = { 'last': 1, }
            for arch in target_archs(self.apiurl, source_project, repo):
                url = osc.core.makeurl(self.apiurl, ['build', source_project, repo, arch, source_package, '_log'], query = query)
                try:
                    result = osc.core.http_GET(url)
                    contents = str(result.read())
                    for entry in self.bad_rpmlint_entries:
                        if (': W: ' + entry in contents) and not (entry in found_entries):
                            self.logger.info(f'found missing whitelist for warning: {entry}')
                            found_entries.add(entry)
                except HTTPError as e:
                    self.logger.info('ERROR in URL %s [%s]' % (url, e))
        return found_entries 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:23,代码来源:check_source.py

示例13: _filter_packages_by_time

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def _filter_packages_by_time(self, packages):
        x = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, '000product', '_history'], {'limit': '1'})))
        producttime = int(x.find('./revision/time').text)
        for pkg in packages:
            try:
                x = ET.fromstring(self.cached_GET(self.makeurl(['source', self.project, pkg, '_history'], {'rev': '1'})))
            # catch deleted packages
            except HTTPError as e:
                if e.code == 404:
                    continue
                raise e

            packagetime = int(x.find('./revision/time').text)
#            if producttime > packagetime:
#                continue
            yield pkg 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:18,代码来源:biarchtool.py

示例14: add_explicit_disable

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def add_explicit_disable(self, wipebinaries=False):

        self._init_biarch_packages()

        resulturl = self.makeurl(['source', self.project])
        result = ET.fromstring(self.cached_GET(resulturl))

        for pkg in self.packages:

            changed = False

            logger.debug("processing %s", pkg)
            if not pkg in self.package_metas:
                logger.error("%s not found", pkg)
                continue
            pkgmeta = self.package_metas[pkg]

            build = pkgmeta.findall("./build")
            if not build:
                logger.debug('disable %s for %s', pkg, self.arch)
                bn = pkgmeta.find('build')
                if bn is None:
                    bn = ET.SubElement(pkgmeta, 'build')
                ET.SubElement(bn, 'disable', { 'arch': self.arch })
                changed = True

            if changed:
                try:
                    pkgmetaurl = self.makeurl(['source', self.project, pkg, '_meta'])
                    self.http_PUT(pkgmetaurl, data=ET.tostring(pkgmeta))
                    if self.caching:
                        self._invalidate__cached_GET(pkgmetaurl)
                    if wipebinaries:
                        self.http_POST(self.makeurl(['build', self.project], {
                            'cmd': 'wipe',
                            'arch': self.arch,
                            'package': pkg }))
                except HTTPError as e:
                    logger.error('failed to update %s: %s', pkg, e) 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:41,代码来源:biarchtool.py

示例15: _setprio

# 需要导入模块: from urllib import error [as 别名]
# 或者: from urllib.error import HTTPError [as 别名]
def _setprio(self, status, priority):
        """
        Set prios for requests that are still in review
        :param project: project to check

        """
        message = 'raising priority for %s' % status.get('name')
        for r in status.findall('missing_reviews/review'):
            reqid = r.get('request')
            req = osc.core.get_request(self.api.apiurl, reqid)
            if req.priority == priority:
                continue
            query = { 'cmd': 'setpriority', 'priority': priority }
            url = osc.core.makeurl(self.api.apiurl, ['request', reqid], query)
            print(f"raising priority of {r.get('package')} [{r.get('request')}] to {priority}")
            try:
                osc.core.http_POST(url, data=message)
            except HTTPError as e:
                print(e) 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:21,代码来源:prio_command.py


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