Opening the browser from Python running in Google Cloud Shell

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Opening the browser from Python running in Google Cloud Shell



I'm developing a small script on Python 3.6, and I'll most likely use it from Google Cloud Shell. In said script, I want to do some API calls, and then, open the web browser with an URL, result of those calls. The following code works in other environments that I have tested on, but not in 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.



Is there anyway to make Python 'tell' Cloud Shell to use the browser from where it's running? i.e: if I'm using Chrome to open Cloud Shell, is there any way to open the link in Chrome? It doesn't matter if it's with webbrowser or other library.




1 Answer
1



Cloud Shell is just a “window” displaying a command line from a remote and temporary Compute Engine virtual machine instance. Meaning that when you run the script, you are actually running it in the remote VM (not in Chrome), and that specific VM does not have a browser by itself.



For example, when you try to run an app in Cloud Shell (here you can find a quick example using "mvn appengine:run"), once the application is running, you will see a message in Cloud Shell, something like:



[INFO] GCLOUD: INFO: Module instance default is running at http://localhost:8080/



If you click on http://localhost:8080/ , you will actually be redirected to the temporary address assigned for the Cloud Shell VM instance (something like 8080-dot-VM-ID-devshell.appspot.com).



In summary, you can’t command Cloud Shell to open the browser with a specific URL shown in the remote VM command line. Also, you should consider that there are outgoing connections limitations and Cloud Shell is intended for interactive use only.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered