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


Python webbrowser.Error方法代码示例

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


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

示例1: _get_browser_controller

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def _get_browser_controller() -> webbrowser.BaseBrowser:

        if get_user_preference("browser") is not None:
            try:
                return webbrowser.get(using=get_user_preference("browser"))
            except webbrowser.Error:
                warnings.warn("Could not find the user preferred browser.")

        for browser in ["chrome", "chromium-browser"]:
            try:
                return webbrowser.get(using=browser)
            except webbrowser.Error:
                pass

        # Return default browser if none of the
        # preferred browsers are installed:
        return webbrowser.get() 
开发者ID:equinor,项目名称:webviz-config,代码行数:19,代码来源:_localhost_open_browser.py

示例2: start_browser

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def start_browser(self, url, name=None):
        browser = None

        if name is not None and name.lower() == 'none':
            log.info('Will not start any browser since --browser=none')
            return

        try:
            browser = webbrowser.get(name)
        except webbrowser.Error:
            old     = name or 'default'
            msg     = 'Could not find browser: %s.  Will use: %s.'
            browser = webbrowser.get()
            log.warn(msg, name, self.getBrowserName(browser))

        if type(browser) is webbrowser.GenericBrowser:
            msg = 'Will not start text-based browser: %s.'
            log.info(msg % self.getBrowserName(browser))
        elif browser is not None:
            log.info('Starting browser: %s' % self.getBrowserName(browser))
            browser.open_new(url) 
开发者ID:NASA-AMMOS,项目名称:AIT-Core,代码行数:23,代码来源:openmct.py

示例3: _run_integration_server

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def _run_integration_server():
    """Runs integration server for interactive debugging."""

    logging.basicConfig(level=logging.INFO)

    logger = logging.getLogger("run_integration_server")

    loop = asyncio.get_event_loop()

    servers = IntegrationServers(False, True)
    logger.info("Starting integration servers...")
    loop.run_until_complete(servers.start_servers())

    try:
        webbrowser.open(servers.origin_server_url)
    except webbrowser.Error:
        pass

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        logger.info("Stopping integration servers...")
        loop.run_until_complete(servers.stop_servers()) 
开发者ID:aio-libs,项目名称:aiohttp-cors,代码行数:27,代码来源:test_real_browser.py

示例4: __init__

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def __init__(self, cmd, args, retcode, stderr):
		'''Constructor

		@param cmd: the application command as string
		@param args: tuple of arguments given to the command
		@param retcode: the return code of the command (non-zero!)
		@param stderr: the error output of the command
		'''
		self.msg = _('Failed to run application: %s') % cmd
			# T: Error message when external application failed, %s is the command
		self.description = \
			_('%(cmd)s\nreturned non-zero exit status %(code)i') \
			% {'cmd': cmd + ' "' + '" "'.join(args) + '"', 'code': retcode}
			# T: Error message when external application failed, %(cmd)s is the command, %(code)i the exit code

		if stderr:
			self.description += '\n\n' + stderr 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:19,代码来源:applications.py

示例5: __init__

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def __init__(self, url, size=None, chromeArgs=[]):
        self.__instance = None

        if sys.platform[:3] == "win":
            exe = find_chrome_win()
        elif sys.platform == "darwin":
            exe = find_chrome_mac()
        else:
            for i in ["chromium-browser", "chromium", "google-chrome", "chrome"]:
                try:
                    exe = webbrowser.get(i).name
                    break
                except webbrowser.Error:
                    exe = None

        if exe:
            args = [exe, "--app=" + url] + chromeArgs
            if size == FULLSCREEN:
                args.append("--start-fullscreen")
            if tempfile.gettempdir():
                args.append(
                    "--user-data-dir=%s"
                    % os.path.join(tempfile.gettempdir(), ".wuyapp")
                )
            # self.__instance = subprocess.Popen( args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) # make troubles on windows (freezd with noconsole don't start)
            self.__instance = subprocess.Popen(args)
        else:
            raise Exception("no browser") 
开发者ID:manatlan,项目名称:wuy,代码行数:30,代码来源:wuy.py

示例6: has_browser

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def has_browser():
    try:
        webbrowser.get()
        return True
    except webbrowser.Error:
        return False 
开发者ID:floydhub,项目名称:floyd-cli,代码行数:8,代码来源:login.py

示例7: set_user_preferences

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def set_user_preferences(
    theme: Optional[str] = None, browser: Optional[str] = None
) -> None:

    preferences = (
        json.loads(USER_SETTINGS_FILE.read_text())
        if USER_SETTINGS_FILE.is_file()
        else {}
    )

    new_preferences = {}

    if theme is not None:
        if theme not in installed_themes:
            raise ValueError(
                f"Theme {theme} is not one of the installed themes ({', '.join(installed_themes)})"
            )
        new_preferences["theme"] = theme

    if browser is not None:
        try:
            webbrowser.get(using=browser)
        except webbrowser.Error:
            raise ValueError(
                f"Could not find an installed browser with the name {browser}."
            )

        new_preferences["browser"] = browser

    if new_preferences:
        preferences.update(new_preferences)
        os.makedirs(USER_SETTINGS_FILE.parent, exist_ok=True)
        USER_SETTINGS_FILE.write_text(json.dumps(preferences)) 
开发者ID:equinor,项目名称:webviz-config,代码行数:35,代码来源:_user_preferences.py

示例8: handle_debug_vm_error

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def handle_debug_vm_error(self, call_id, payload):
        self.editor.raw_message('Error. Check ensime-vim log for details.') 
开发者ID:ensime,项目名称:ensime-vim,代码行数:4,代码来源:protocol.py

示例9: _browse_doc

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def _browse_doc(self, url):
        self.log.debug('_browse_doc: %s', url)
        try:
            if webbrowser.open(url):
                self.log.info('opened %s', url)
        except webbrowser.Error:
            self.log.exception('_browse_doc: webbrowser error')
            self.editor.raw_message(feedback["manual_doc"].format(url)) 
开发者ID:ensime,项目名称:ensime-vim,代码行数:10,代码来源:protocol.py

示例10: open_url

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def open_url(url: str):
    """Filter ugly terminal output when using webbrowser.

    When using webbrowser.open the follow error is shown:
    [20451:20471:0313/132752.481635:ERROR:browser_process_sub_thread.cc(209)]
    Waited 3 ms for network service.
    In attempts to improve UX when using the CLI, we are surpressing that
    error with the following utility. For more information refer to:
    http://man7.org/linux/man-pages/man2/dup.2.html
    """

    # Save previous standard file descriptors
    prev_stderr_fd = os.dup(2)
    prev_stdout_fd = os.dup(1)
    with open(os.devnull, 'wb') as f:
        # redirect stderr and stdout to os.devnull
        os.dup2(f.fileno(), 2)
        os.dup2(f.fileno(), 1)
        try:
            webbrowser.open(url)
        except webbrowser.Error:
            # We are not able to do anything if any internal errors happen
            # with webbrowser.open()
            pass
        finally:
            # restore stdout and stderr
            os.dup2(prev_stdout_fd, 1)
            os.dup2(prev_stderr_fd, 2) 
开发者ID:GoogleCloudPlatform,项目名称:django-cloud-deploy,代码行数:30,代码来源:webbrowser.py

示例11: open_webbrowser

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def open_webbrowser(address):
    print("Your browser has been opened to visit")
    try:
        webbrowser.open(url=address, new=1)
    except webbrowser.Error as e:
        print("Unable to open the web browser: {}".format(e))
        sys.exit() 
开发者ID:IntelAI,项目名称:inference-model-manager,代码行数:9,代码来源:webbrowser_authenticate.py

示例12: open_link

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def open_link(url, name_of_link):
  """Open the given URL in the user's default webbrowser."""
  try:
    # If possible, open in a new tab, and raise the window to the front
    webbrowser.open(url, new=2, autoraise=True)
    return True
  except webbrowser.Error:
    sys.stderr.write("\t" + name_of_link + " failed to open.\n")
    return False 
开发者ID:google,项目名称:fplutil,代码行数:11,代码来源:util.py

示例13: run

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def run(self):
        try:
            webbrowser.open(self.server_url)
        except webbrowser.Error:
            raise SystemExit('ERROR! Unable to open browser. '
                             'Please manually launch a browser and '
                             'navitage to this url: "%s".' % self.server_url) 
开发者ID:StanfordBioinformatics,项目名称:loom,代码行数:9,代码来源:browser.py

示例14: run

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def run(self, force_console=False):
        """Run the flow using a local server if possible, otherwise the
        console."""
        # TODO(b/141721828): make auto-detection smarter, especially for macOS.
        if not force_console and os.getenv("DISPLAY"):
            try:
                return self.run_local_server(port=0)
            except webbrowser.Error:
                sys.stderr.write(
                    "Falling back to console authentication flow...\n"
                )
        return self.run_console() 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:14,代码来源:auth.py

示例15: autodocs

# 需要导入模块: import webbrowser [as 别名]
# 或者: from webbrowser import Error [as 别名]
def autodocs():
    "create Sphinx docs locally, and start a watchdog"
    build_dir = path('docs/_build')
    index_html = build_dir / 'html/index.html'
    if build_dir.exists():
        build_dir.rmtree()

    with pushd("docs"):
        print "\n*** Generating API doc ***\n"
        sh("sphinx-apidoc -o apidoc -f -T ../src/pyrocore")
        sh("sphinx-apidoc -o apidoc -f -T $(dirname $(python -c 'import tempita; print(tempita.__file__)'))")
        print "\n*** Generating HTML doc ***\n"
        sh('command . ../bin/activate && '
           'nohup %s/Makefile SPHINXBUILD="sphinx-autobuild -p %d'
           ' -i \'.*\' -i \'*.log\' -i \'*.png\' -i \'*.txt\'" html >autobuild.log 2>&1 &'
           % (os.getcwd(), SPHINX_AUTOBUILD_PORT))

    for i in range(25):
        time.sleep(2.5)
        pid = watchdog_pid()
        if pid:
            sh("touch docs/index.rst")
            sh('ps {}'.format(pid))
            url = 'http://localhost:{port:d}/'.format(port=SPHINX_AUTOBUILD_PORT)
            try:
                import webbrowser
                webbrowser.open_new_tab(url)
            except webbrowser.Error:
                print("\n*** Open '{}' in your browser...".format(url))
            break 
开发者ID:pyroscope,项目名称:pyrocore,代码行数:32,代码来源:pavement.py


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