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.
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.
Related
I'm running a python script in the AWS Workspaces to take a screensot of my entire desktop (inside AWS).
The script is working fine but when I "ended" the AWS Workspace, the screenshot being taken is the login page. Please find attached.
Inside the AWS Workspace, I already did any possible ways to prevent "my computer" from sleeping. Likewise, its Running Mode is AlwaysOn.
What I want to achieve is even though my AWS Workspace is not "active" I want my python script to capture the active desktop not the login page.
I've been following the instructions for this guide:
https://developers.google.com/gmail/api/quickstart/python
to run a basic program which reads a Gmail inbox.
Basically, the program opens up a new window asking you to login with your gmail account - once that is done, it gives the information back to the program which should print results on the google cloud shell terminal.
Whenever I login with the correct google account, the page shows "localhost refused to connect". For this reason, the rest of the program cannot continue, so the google cloud shell is stuck waiting for the login to occur. Would anyone have any ideas on why this localhost error is happening? Thanks in advance.
Solution
Run the code from your desktop.
The OAuth Flow that you are using requires a web browser. This means the webserver process must be running on your system.
You are trying to run code in Cloud Shell. And it does not have one. If you look at the source code run_local_server() starts a webserver. The server is running on the wrong system.
There are methods to create a public webserver (not using localhost). Then the issue becomes how to start the webserver on Cloud Shell.
Except for experimenting you are using the wrong services (Cloud Shell).
I am trying mirror a process on Windows that I use on linux for creating an automated build of an application web server. The only way to have full automation is to have some sort of EXPECT utility for the interactions on the CLI.
We use a script to setup all the configuration and settings for our applications web servers that is easily portable to batch since the web server is windows compatible as well with the same commands.
I've basically got it down for Linux, however the flip side to this is that the windows doesn't seem to have a clear expect alternative.
Any suggestions to allow it to send a response when prompted and continue the rest of the scripted process would be most helpful.
I trying to open a browser from cloud shell. I have firefox installed in cloud shell but can't launch it.
getting this error :
XPCOMGlueLoad error for file ...../firefox/libxul.so:
libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
I found a couple of solutions on Google but didn't work. So thought of checking if it's allowed to launch a browser from Azure cloud Shell or not?
Probably, It's not allowed to do that since cloud shell offers a browser-accessible, pre-configured shell experience for managing Azure resources without the overhead of installing, versioning, and maintaining a machine yourself.
You could get more details about Features & tools for Azure Cloud Shell.
No, this is not possible, because its a guiless container. so there is no video in the container. you can only use tty
Is there a way to launch a bash/ksh shell, or execute a shell script from Chromium? Is there a setting to tweak, a plungin to add, a workaround besides php and a local server?
Sorry if this is a duplicate. I assumed I would find an answer here, but only see answers about launching Chromium using a script or complete workarounds avoiding my question, with a local server and JavaScript/PHP. I have an Apache server available and can do the coding, but rather not.
I could do this in Internet Explorer on Windows (or used to be able to launch a .bat script there. I haven't used IE in a long time), why not in Chromium on Linux?
I understand the security concerns and sandbox in the browser, but in this case the browser never goes outside a firewall and I just want to launch a script from Chromium.
Thank you for your thoughtful replies.