代码之家  ›  专栏  ›  技术社区  ›  AntonioGarcía

从运行在google cloud shell中的python打开浏览器

  •  2
  • AntonioGarcía  · 技术社区  · 8 年前

    我正在python 3.6上开发一个小脚本,我很可能会从google cloud shell中使用它。在上述脚本中,我想做一些api调用,然后,打开带有url的web浏览器,这些调用的结果。以下代码适用于我测试过的其他环境,但不适用于Cloud Shell:

    import webbrowser as wb
    # different calls and process here, not relevant to the issue 
    wb.open('URL_HERE')
    #This just echoes the URL.
    

    有没有办法让python“告诉”cloud shell从它运行的地方使用浏览器?例如:如果我使用chrome来打开云壳,有没有办法在chrome中打开链接?不管是韦布罗瑟还是其他图书馆。

    1 回复  |  直到 8 年前
        1
  •  0
  •   JC98    8 年前

    cloud shell只是一个“窗口”,显示来自远程和 temporary Compute Engine virtual machine instance . 这意味着当运行脚本时,实际上是在远程vm(而不是chrome)中运行它,并且特定vm本身没有浏览器。

    例如,当您尝试在云shell中运行应用程序时( here 您可以使用“mvn appengine:run”找到一个快速示例,应用程序运行后,您将在cloud shell中看到一条消息,如下所示:

    [信息]gcloud:info:模块实例默认运行于 http://localhost:8080/

    如果你点击 http://localhost:8080/ ,实际上您将被重定向到为cloud shell vm实例分配的临时地址(类似于8080 dot vm id devshell.appspot.com)。

    总之,您不能命令cloud shell使用远程vm命令行中显示的特定url打开浏览器。而且,你应该考虑到 outgoing connections limitations 云壳的目的是 interactive use 只有。